From dfb75e19dbc05a7a834b60369d5606dc5d548427 Mon Sep 17 00:00:00 2001 From: Padsala Tushal Date: Tue, 7 Nov 2023 12:16:00 +0530 Subject: [PATCH] convert verboselogon checkbox into toggle button --- config/tweaks.json | 11 ---- functions/private/Get-WinUtilToggleStatus.ps1 | 9 +++ .../private/Invoke-WinUtilVerboseLogon.ps1 | 31 ++++++++++ functions/public/Invoke-WPFToggle.ps1 | 1 + winutil.ps1 | 59 +++++++++++++++---- xaml/inputXML.xaml | 7 ++- 6 files changed, 94 insertions(+), 24 deletions(-) create mode 100644 functions/private/Invoke-WinUtilVerboseLogon.ps1 diff --git a/config/tweaks.json b/config/tweaks.json index 67e5c7966d..db29ed7e3b 100644 --- a/config/tweaks.json +++ b/config/tweaks.json @@ -2355,17 +2355,6 @@ } ] }, - "WPFMiscTweaksEnableVerboselogon": { - "registry": [ - { - "Path": "HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\policies\\system", - "OriginalValue": "0", - "Name": "VerboseStatus", - "Value": "1", - "Type": "DWord" - } - ] - }, "WPFEssTweaksDeleteTempFiles": { "InvokeScript": [ "Get-ChildItem -Path \"C:\\Windows\\Temp\" *.* -Recurse | Remove-Item -Force -Recurse diff --git a/functions/private/Get-WinUtilToggleStatus.ps1 b/functions/private/Get-WinUtilToggleStatus.ps1 index 61d6eff5d6..2bed199663 100644 --- a/functions/private/Get-WinUtilToggleStatus.ps1 +++ b/functions/private/Get-WinUtilToggleStatus.ps1 @@ -40,5 +40,14 @@ Function Get-WinUtilToggleStatus { else{ return $false } + } + if($ToggleSwitch -eq "WPFToggleVerboseLogon"){ + $VerboseStatusvalue = (Get-ItemProperty -path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System').VerboseStatus + if($VerboseStatusvalue -eq 1){ + return $true + } + else{ + return $false + } } } \ No newline at end of file diff --git a/functions/private/Invoke-WinUtilVerboseLogon.ps1 b/functions/private/Invoke-WinUtilVerboseLogon.ps1 new file mode 100644 index 0000000000..997050f9db --- /dev/null +++ b/functions/private/Invoke-WinUtilVerboseLogon.ps1 @@ -0,0 +1,31 @@ +function Invoke-WinUtilVerboseLogon { + <# + .SYNOPSIS + Disables/Enables VerboseLogon Messages + .PARAMETER Enabled + Indicates whether to enable or disable VerboseLogon messages + #> + Param($Enabled) + Try{ + if ($Enabled -eq $false){ + Write-Host "Enabling Verbose Logon Messages" + $value = 1 + } + else { + Write-Host "Disabling Verbose Logon Messages" + $value = 0 + } + $Path = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" + Set-ItemProperty -Path $Path -Name VerboseStatus -Value $value + } + Catch [System.Security.SecurityException] { + Write-Warning "Unable to set $Path\$Name to $Value due to a Security Exception" + } + Catch [System.Management.Automation.ItemNotFoundException] { + Write-Warning $psitem.Exception.ErrorRecord + } + Catch{ + Write-Warning "Unable to set $Name due to unhandled exception" + Write-Warning $psitem.Exception.StackTrace + } +} \ No newline at end of file diff --git a/functions/public/Invoke-WPFToggle.ps1 b/functions/public/Invoke-WPFToggle.ps1 index edc011b99a..e2c68431d5 100644 --- a/functions/public/Invoke-WPFToggle.ps1 +++ b/functions/public/Invoke-WPFToggle.ps1 @@ -20,5 +20,6 @@ function Invoke-WPFToggle { "WPFToggleDarkMode" {Invoke-WinUtilDarkMode -DarkMoveEnabled $(Get-WinUtilToggleStatus WPFToggleDarkMode)} "WPFToggleBingSearch" {Invoke-WinUtilBingSearch $(Get-WinUtilToggleStatus WPFToggleBingSearch)} "WPFToggleNumLock" {Invoke-WinUtilNumLock $(Get-WinUtilToggleStatus WPFToggleNumLock)} + "WPFToggleVerboseLogon" {Invoke-WinUtilVerboseLogon $(Get-WinUtilToggleStatus WPFToggleVerboseLogon)} } } \ No newline at end of file diff --git a/winutil.ps1 b/winutil.ps1 index fcf1fbe697..40ebe39dbb 100755 --- a/winutil.ps1 +++ b/winutil.ps1 @@ -204,6 +204,15 @@ Function Get-WinUtilToggleStatus { else{ return $false } + } + if($ToggleSwitch -eq "WPFToggleVerboseLogon"){ + $VerboseStatusvalue = (Get-ItemProperty -path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System').VerboseStatus + if($VerboseStatusvalue -eq 1){ + return $true + } + else{ + return $false + } } } function Get-WinUtilVariables { @@ -727,6 +736,37 @@ function Invoke-WinUtilTweaks { } } +function Invoke-WinUtilVerboseLogon { + <# + .SYNOPSIS + Disables/Enables VerboseLogon Messages + .PARAMETER Enabled + Indicates whether to enable or disable VerboseLogon messages + #> + Param($Enabled) + Try{ + if ($Enabled -eq $false){ + Write-Host "Enabling Verbose Logon Messages" + $value = 1 + } + else { + Write-Host "Disabling Verbose Logon Messages" + $value = 0 + } + $Path = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" + Set-ItemProperty -Path $Path -Name VerboseStatus -Value $value + } + Catch [System.Security.SecurityException] { + Write-Warning "Unable to set $Path\$Name to $Value due to a Security Exception" + } + Catch [System.Management.Automation.ItemNotFoundException] { + Write-Warning $psitem.Exception.ErrorRecord + } + Catch{ + Write-Warning "Unable to set $Name due to unhandled exception" + Write-Warning $psitem.Exception.StackTrace + } +} function Remove-WinUtilAPPX { <# @@ -1744,6 +1784,7 @@ function Invoke-WPFToggle { "WPFToggleDarkMode" {Invoke-WinUtilDarkMode -DarkMoveEnabled $(Get-WinUtilToggleStatus WPFToggleDarkMode)} "WPFToggleBingSearch" {Invoke-WinUtilBingSearch $(Get-WinUtilToggleStatus WPFToggleBingSearch)} "WPFToggleNumLock" {Invoke-WinUtilNumLock $(Get-WinUtilToggleStatus WPFToggleNumLock)} + "WPFToggleVerboseLogon" {Invoke-WinUtilVerboseLogon $(Get-WinUtilToggleStatus WPFToggleVerboseLogon)} } } function Invoke-WPFtweaksbutton { @@ -2778,7 +2819,12 @@ $inputXML = ' - +