diff --git a/Win11Tweaker/DialogForm.cs b/Win11Tweaker/DialogForm.cs index a2e70ea..f4a9124 100644 --- a/Win11Tweaker/DialogForm.cs +++ b/Win11Tweaker/DialogForm.cs @@ -1,5 +1,5 @@ using System; -using System.Management.Automation; +using System.Diagnostics; using System.Windows.Forms; using WinBlur; @@ -26,29 +26,25 @@ private void negativeBtn_Click(object sender, EventArgs e) private void positiveBtn_Click(object sender, EventArgs e) { - using (PowerShell ps = PowerShell.Create()) - { + switch (Properties.Settings.Default.val) { - case 0: - ps.AddScript(@" -Stop-Process -name explorer - - "); - break; - case 1: - ps.AddScript(@" - -Shutdown -l - "); - break; - } + case 0: + Process[] explorerProcesses = Process.GetProcessesByName("explorer"); + foreach (Process process in explorerProcesses) + { + process.Kill(); + } + break; + case 1: + Process.Start("shutdown", "-l"); + break; + } - var output = ps.Invoke(); this.Close(); - } + } } } diff --git a/Win11Tweaker/Form1.cs b/Win11Tweaker/Form1.cs index 3248c02..da8c36b 100644 --- a/Win11Tweaker/Form1.cs +++ b/Win11Tweaker/Form1.cs @@ -1,13 +1,11 @@ -using System; +using Microsoft.Win32; +using System; using System.Drawing; -using System.Management.Automation; using System.Reflection; -using System.Reflection.Emit; using System.Windows.Forms; using Win11Tweaker.Properties; using WinBlur; -using static System.Windows.Forms.VisualStyles.VisualStyleElement; -using static System.Windows.Forms.VisualStyles.VisualStyleElement.ToolBar; + using Label = System.Windows.Forms.Label; namespace Win11Tweaker @@ -16,10 +14,10 @@ public partial class Form1 : Form { private DialogForm dialog; private bool appLoaded = false; - + public Form1() { - + InitializeComponent(); dialog = new DialogForm(); @@ -31,10 +29,10 @@ public Form1() getPref(Settings.Default.printScrChecked, printScrSwitch); Console.WriteLine(appLoaded); - - + + } - + private void onPaint(object sender, PaintEventArgs e) { Label label = (Label)sender; @@ -63,16 +61,16 @@ private void onPaint(object sender, PaintEventArgs e) drawBrush.Dispose(); sf.Dispose(); customFont.Dispose(); - + } - private void setPreview(Point location,Size size,Bitmap image,string Title,string Desc) + private void setPreview(Point location, Size size, Bitmap image, string Title, string Desc) { preview.Image = image; preview.Location = location; preview.Size = size; previewTitle.Text = Title; - previewDesc.Text =Desc; + previewDesc.Text = Desc; } private void Form1_Load(object sender, EventArgs e) @@ -82,7 +80,7 @@ private void Form1_Load(object sender, EventArgs e) appLoaded = true; Console.WriteLine(appLoaded); UI.SetBlurStyle(cntrl: panel2, blurType: UI.BlurType.Mica, designMode: UI.Mode.DarkMode); - + } @@ -125,18 +123,18 @@ private void contextMenuSwitch_CheckedChanged(object sender, EventArgs e) if (contextMenuSwitch.Checked) { setPref(nameof(Settings.Default.contextMenuChecked), true); - RunScript(nameof(Settings.Default.contextMenuChecked), true); + runReg(nameof(Settings.Default.contextMenuChecked), true); } else { setPref(nameof(Settings.Default.contextMenuChecked), false); - RunScript(nameof(Settings.Default.contextMenuChecked), false); + runReg(nameof(Settings.Default.contextMenuChecked), false); } - + } private void webSearchSwitch_CheckedChanged(object sender, EventArgs e) @@ -144,13 +142,13 @@ private void webSearchSwitch_CheckedChanged(object sender, EventArgs e) if (webSearchSwitch.Checked) { setPref(nameof(Settings.Default.webSearchChecked), true); - RunScript(nameof(Settings.Default.webSearchChecked), true); + runReg(nameof(Settings.Default.webSearchChecked), true); } else { setPref(nameof(Settings.Default.webSearchChecked), false); - RunScript(nameof(Settings.Default.webSearchChecked), false); + runReg(nameof(Settings.Default.webSearchChecked), false); } @@ -161,12 +159,12 @@ private void lockScreenSwitch_CheckedChanged(object sender, EventArgs e) if (lockScreenSwitch.Checked) { setPref(nameof(Settings.Default.lockScreennChecked), true); - RunScript(nameof(Settings.Default.lockScreennChecked), true); + runReg(nameof(Settings.Default.lockScreennChecked), true); } else { setPref(nameof(Settings.Default.lockScreennChecked), false); - RunScript(nameof(Settings.Default.lockScreennChecked), false); + runReg(nameof(Settings.Default.lockScreennChecked), false); } } @@ -176,12 +174,12 @@ private void compactViewSwitch_CheckedChanged(object sender, EventArgs e) if (compactViewSwitch.Checked) { setPref(nameof(Settings.Default.compactViewChecked), true); - RunScript(nameof(Settings.Default.compactViewChecked), true); + runReg(nameof(Settings.Default.compactViewChecked), true); } else { setPref(nameof(Settings.Default.compactViewChecked), false); - RunScript(nameof(Settings.Default.compactViewChecked), false); + runReg(nameof(Settings.Default.compactViewChecked), false); } } @@ -191,12 +189,12 @@ private void previewPaneSwitch_CheckedChanged(object sender, EventArgs e) if (previewPaneSwitch.Checked) { setPref(nameof(Settings.Default.previewPaneChecked), true); - RunScript(nameof(Settings.Default.previewPaneChecked), true); + runReg(nameof(Settings.Default.previewPaneChecked), true); } else { setPref(nameof(Settings.Default.previewPaneChecked), false); - RunScript(nameof(Settings.Default.previewPaneChecked), false); + runReg(nameof(Settings.Default.previewPaneChecked), false); } @@ -206,291 +204,515 @@ private void printScrSwitch_CheckedChanged(object sender, EventArgs e) { if (printScrSwitch.Checked) { - setPref(nameof(Settings.Default.printScrChecked), true); RunScript(nameof(Settings.Default.previewPaneChecked), false); - RunScript(nameof(Settings.Default.printScrChecked), true); + setPref(nameof(Settings.Default.printScrChecked), true); runReg(nameof(Settings.Default.previewPaneChecked), false); + runReg(nameof(Settings.Default.printScrChecked), true); } else { setPref(nameof(Settings.Default.printScrChecked), false); - RunScript(nameof(Settings.Default.printScrChecked), false); + runReg(nameof(Settings.Default.printScrChecked), false); } } - private void RunScript(string key, bool isChecked) + + + + // Method to set a registry value + private static void SetHKLMRegistryValue(string keyPath, string valueName, object value) { - if (appLoaded) + + + using (RegistryKey key = Registry.LocalMachine.OpenSubKey(keyPath, true)) { - using (PowerShell ps = PowerShell.Create()) + if (key != null) + { + key.SetValue(valueName, value); + } + else { - switch (key) + // Key not found, create it + using (RegistryKey newKey = Registry.LocalMachine.CreateSubKey(keyPath)) { - case nameof(Settings.Default.contextMenuChecked): - if (isChecked) - { - ps.AddScript(@" -# Enable Classic Context Menu -$regPath = ""HKCU:\Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32"" - -# Check if the registry key exists -if (-not (Test-Path $regPath)) { - # Create the registry key if it doesn't exist - New-Item -Path $regPath -Force | Out-Null -} - -# Set the default value -Set-ItemProperty -Path $regPath -Name ""(Default)"" -Value """" + if (newKey != null) + { + newKey.SetValue(valueName, value); + } + else + { + Console.WriteLine("ERROR: Failed to create key - " + keyPath); + } + } + } + } + } + // Method to set a registry value + private static void SetROOTRegistryValue(string keyPath, string valueName, object value) + { -#RESTART EXPLORER!! - "); + using (RegistryKey key = Registry.ClassesRoot.OpenSubKey(keyPath, true)) + { + if (key != null) + { + key.SetValue(valueName, value); + } + else + { + // Key not found, create it + using (RegistryKey newKey = Registry.ClassesRoot.CreateSubKey(keyPath)) + { + if (newKey != null) + { + newKey.SetValue(valueName, value); + } + else + { + Console.WriteLine("ERROR: Failed to create key - " + keyPath); + } + } + } + } + } + private static void SetHKCURegistryValue(string keyPath, string valueName, object value) + { - } - else - { - ps.AddScript(@" -# Disable Classic Context Menu -$regPath = ""REGISTRY::HKEY_CURRENT_USER\Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}"" -Remove-Item -Path $regPath -Recurse -Force -ErrorAction SilentlyContinue -ErrorVariable RemoveError -if ($RemoveError) { - Write-Host ""Error removing registry path: $regPath"" - Write-Host $RemoveError -} -else { - Write-Host ""Registry path removed successfully: $regPath"" -} + using (RegistryKey key = Registry.CurrentUser.OpenSubKey(keyPath, true)) + { + if (key != null) + { + key.SetValue(valueName, value); + } + else + { + // Key not found, create it + using (RegistryKey newKey = Registry.CurrentUser.CreateSubKey(keyPath)) + { + if (newKey != null) + { + newKey.SetValue(valueName, value); + } + else + { + Console.WriteLine("ERROR: Failed to create key - " + keyPath); + } + } + } + } + } + // Method to delete a registry key + private static void DeleteHKCURegistryKey(string keyPath) + { + Registry.CurrentUser.DeleteSubKeyTree(keyPath, false); + } + private static void DeleteHKLMRegistryKey(string keyPath) + { + Registry.LocalMachine.DeleteSubKeyTree(keyPath, false); + } + private static void DeleteROOTRegistryKey(string keyPath) + { + Registry.ClassesRoot.DeleteSubKeyTree(keyPath, false); + } -# RESTART EXPLORER!! - - "); - - } - onRestartExplorer(); - break; - case nameof(Settings.Default.webSearchChecked): - if (isChecked) - { - ps.AddScript(@" -# Disable Web Search -Set-ItemProperty -Path ""HKCU:\SOFTWARE\Policies\Microsoft\Windows\Explorer"" -Name ""DisableSearchBoxSuggestions"" -Value 1 - -#SIGNOUT - -"); - } - else - { - ps.AddScript(@" -# Enable Web Search -Remove-ItemProperty -Path ""HKCU:\SOFTWARE\Policies\Microsoft\Windows\Explorer"" -Name ""DisableSearchBoxSuggestions"" -ErrorAction SilentlyContinue -#SIGNOUT - -"); - } - onSignOut(); - break; - case nameof(Settings.Default.lockScreennChecked): - if (isChecked) - { - ps.AddScript(@" -#Disable Lock Screen -$RegistryPath = ""HKLM:\SOFTWARE\Policies\Microsoft\Windows"" -$PersonalizationKey = ""Personalization"" -$NoLockScreenValueName = ""NoLockScreen"" -$NoLockScreenValueData = 1 - -# Create or open the Personalization key -New-Item -Path $RegistryPath -Name $PersonalizationKey -Force | Out-Null - -# Set the NoLockScreen value under the Personalization key -Set-ItemProperty -Path ""$RegistryPath\$PersonalizationKey"" -Name $NoLockScreenValueName -Value $NoLockScreenValueData -Type DWORD -Force - -"); - } - else - { - ps.AddScript(@" -#Enable Lock Screen -$RegistryPath = ""HKLM:\SOFTWARE\Policies\Microsoft\Windows"" -$PersonalizationKey = ""Personalization"" -$NoLockScreenValueName = ""NoLockScreen"" -$NoLockScreenValueData = 0 - -# Create or open the Personalization key -New-Item -Path $RegistryPath -Name $PersonalizationKey -Force | Out-Null - -# Set the NoLockScreen value under the Personalization key -Set-ItemProperty -Path ""$RegistryPath\$PersonalizationKey"" -Name $NoLockScreenValueName -Value $NoLockScreenValueData -Type DWORD -Force - -"); - } - break; - case nameof(Settings.Default.compactViewChecked): - if (isChecked) - { - ps.AddScript(@" -#Enable Compact View -$RegistryPath = ""HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced"" -$UseCompactModeValueName = ""UseCompactMode"" -$UseCompactModeValueData = 1 - -# Check if the UseCompactMode value exists -if (!(Test-Path ""$RegistryPath\$UseCompactModeValueName"")) { - # Create the UseCompactMode value if it doesn't exist - New-ItemProperty -Path $RegistryPath -Name $UseCompactModeValueName -PropertyType DWORD -Value $UseCompactModeValueData -Force | Out-Null - Write-Host ""Value '$UseCompactModeValueName' created with value '$UseCompactModeValueData'."" -} else { - # Modify the existing UseCompactMode value - Set-ItemProperty -Path $RegistryPath -Name $UseCompactModeValueName -Value $UseCompactModeValueData -Force - Write-Host ""Value '$UseCompactModeValueName' modified to '$UseCompactModeValueData'."" -} - "); - } - else - { - ps.AddScript(@" -#Disable Compact View -$RegistryPath = ""HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced"" -$UseCompactModeValueName = ""UseCompactMode"" -$UseCompactModeValueData = 0 - -# Check if the UseCompactMode value exists -if (!(Test-Path ""$RegistryPath\$UseCompactModeValueName"")) { - # Create the UseCompactMode value if it doesn't exist - New-ItemProperty -Path $RegistryPath -Name $UseCompactModeValueName -PropertyType DWORD -Value $UseCompactModeValueData -Force | Out-Null - Write-Host ""Value '$UseCompactModeValueName' created with value '$UseCompactModeValueData'."" -} else { - # Modify the existing UseCompactMode value - Set-ItemProperty -Path $RegistryPath -Name $UseCompactModeValueName -Value $UseCompactModeValueData -Force - Write-Host ""Value '$UseCompactModeValueName' modified to '$UseCompactModeValueData'."" -} + private void runReg(string key, bool isChecked) + { + if (appLoaded) + { + string keyPath; + switch (key) + { + case nameof(Settings.Default.contextMenuChecked): + keyPath = @"Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32"; + if (isChecked) + { + SetHKCURegistryValue(keyPath, "", ""); + } + else + { + DeleteHKCURegistryKey(keyPath); + } + onRestartExplorer(); + break; + case nameof(Settings.Default.webSearchChecked): + keyPath = @"SOFTWARE\Policies\Microsoft\Windows\Explorer"; + if (isChecked) + { + SetHKCURegistryValue(keyPath, "DisableSearchBoxSuggestions", 1); + } + else + { + Registry.CurrentUser.OpenSubKey(keyPath, true)?.DeleteValue("DisableSearchBoxSuggestions", false); + } + break; + case nameof(Settings.Default.lockScreennChecked): + keyPath = @"SOFTWARE\Policies\Microsoft\Windows\Personalization"; + if (isChecked) + { + SetHKLMRegistryValue(keyPath, "NoLockScreen", 1); + } + else + { + SetHKLMRegistryValue(keyPath, "NoLockScreen", 0); + } + break; + case nameof(Settings.Default.compactViewChecked): + keyPath = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced"; + if (isChecked) + { + SetHKCURegistryValue(keyPath, "UseCompactMode", 1); + } + else + { + SetHKCURegistryValue(keyPath, "UseCompactMode", 0); + } + break; + case nameof(Settings.Default.previewPaneChecked): + keyPath = @"AllFilesystemObjects\shell\Windows.previewpane"; + if (isChecked) + { + SetROOTRegistryValue(keyPath, "CanonicalName", "{1380d028-a77f-4c12-96c7-ea276333f982}"); + SetROOTRegistryValue(keyPath, "Description", "@shell32.dll,-31416"); + SetROOTRegistryValue(keyPath, "Icon", "shell32.dll,-16814"); + SetROOTRegistryValue(keyPath, "MUIVerb", "@shell32.dll,-31415"); + SetROOTRegistryValue(keyPath, "PaneID", "{43abf98b-89b8-472d-b9ce-e69b8229f019}"); + SetROOTRegistryValue(keyPath, "PaneVisibleProperty", "PreviewPaneSizer_Visible"); + SetROOTRegistryValue(keyPath, "PolicyID", "{17067f8d-981b-42c5-98f8-5bc016d4b073}"); + + keyPath = @"Directory\Background\shell\Windows.previewpane"; + SetROOTRegistryValue(keyPath, "CanonicalName", "{1380d028-a77f-4c12-96c7-ea276333f982}"); + SetROOTRegistryValue(keyPath, "Description", "@shell32.dll,-31416"); + SetROOTRegistryValue(keyPath, "Icon", "shell32.dll,-16814"); + SetROOTRegistryValue(keyPath, "MUIVerb", "@shell32.dll,-31415"); + SetROOTRegistryValue(keyPath, "PaneID", "{43abf98b-89b8-472d-b9ce-e69b8229f019}"); + SetROOTRegistryValue(keyPath, "PaneVisibleProperty", "PreviewPaneSizer_Visible"); + SetROOTRegistryValue(keyPath, "PolicyID", "{17067f8d-981b-42c5-98f8-5bc016d4b073}"); + + keyPath = @"Drive\shell\Windows.previewpane"; + SetROOTRegistryValue(keyPath, "CanonicalName", "{1380d028-a77f-4c12-96c7-ea276333f982}"); + SetROOTRegistryValue(keyPath, "Description", "@shell32.dll,-31416"); + SetROOTRegistryValue(keyPath, "Icon", "shell32.dll,-16814"); + SetROOTRegistryValue(keyPath, "MUIVerb", "@shell32.dll,-31415"); + SetROOTRegistryValue(keyPath, "PaneID", "{43abf98b-89b8-472d-b9ce-e69b8229f019}"); + SetROOTRegistryValue(keyPath, "PaneVisibleProperty", "PreviewPaneSizer_Visible"); + SetROOTRegistryValue(keyPath, "PolicyID", "{17067f8d-981b-42c5-98f8-5bc016d4b073}"); + + keyPath = @"LibraryFolder\background\shell\Windows.previewpane"; + SetROOTRegistryValue(keyPath, "CanonicalName", "{1380d028-a77f-4c12-96c7-ea276333f982}"); + SetROOTRegistryValue(keyPath, "Description", "@shell32.dll,-31416"); + SetROOTRegistryValue(keyPath, "Icon", "shell32.dll,-16814"); + SetROOTRegistryValue(keyPath, "MUIVerb", "@shell32.dll,-31415"); + SetROOTRegistryValue(keyPath, "PaneID", "{43abf98b-89b8-472d-b9ce-e69b8229f019}"); + SetROOTRegistryValue(keyPath, "PaneVisibleProperty", "PreviewPaneSizer_Visible"); + SetROOTRegistryValue(keyPath, "PolicyID", "{17067f8d-981b-42c5-98f8-5bc016d4b073}"); + } + else + { + keyPath = @"AllFilesystemObjects\shell\Windows.previewpane"; + DeleteROOTRegistryKey(keyPath); - "); - } - break; - case nameof(Settings.Default.previewPaneChecked): - if (isChecked) - { - ps.AddScript(@" -# Enable Preview Pane -$registryPath = ""REGISTRY::HKEY_CLASSES_ROOT\AllFilesystemObjects\shell\Windows.previewpane"" -New-Item -Path $registryPath -Force | Out-Null -Set-ItemProperty -Path $registryPath -Name ""CanonicalName"" -Value ""{1380d028-a77f-4c12-96c7-ea276333f982}"" -Set-ItemProperty -Path $registryPath -Name ""Description"" -Value ""@shell32.dll,-31416"" -Set-ItemProperty -Path $registryPath -Name ""Icon"" -Value ""shell32.dll,-16814"" -Set-ItemProperty -Path $registryPath -Name ""MUIVerb"" -Value ""@shell32.dll,-31415"" -Set-ItemProperty -Path $registryPath -Name ""PaneID"" -Value ""{43abf98b-89b8-472d-b9ce-e69b8229f019}"" -Set-ItemProperty -Path $registryPath -Name ""PaneVisibleProperty"" -Value ""PreviewPaneSizer_Visible"" -Set-ItemProperty -Path $registryPath -Name ""PolicyID"" -Value ""{17067f8d-981b-42c5-98f8-5bc016d4b073}"" - -$registryPath = ""REGISTRY::HKEY_CLASSES_ROOT\Directory\Background\shell\Windows.previewpane"" -New-Item -Path $registryPath -Force | Out-Null -Set-ItemProperty -Path $registryPath -Name ""CanonicalName"" -Value ""{1380d028-a77f-4c12-96c7-ea276333f982}"" -Set-ItemProperty -Path $registryPath -Name ""Description"" -Value ""@shell32.dll,-31416"" -Set-ItemProperty -Path $registryPath -Name ""Icon"" -Value ""shell32.dll,-16814"" -Set-ItemProperty -Path $registryPath -Name ""MUIVerb"" -Value ""@shell32.dll,-31415"" -Set-ItemProperty -Path $registryPath -Name ""PaneID"" -Value ""{43abf98b-89b8-472d-b9ce-e69b8229f019}"" -Set-ItemProperty -Path $registryPath -Name ""PaneVisibleProperty"" -Value ""PreviewPaneSizer_Visible"" -Set-ItemProperty -Path $registryPath -Name ""PolicyID"" -Value ""{17067f8d-981b-42c5-98f8-5bc016d4b073}"" - -$registryPath = ""REGISTRY::HKEY_CLASSES_ROOT\Drive\shell\Windows.previewpane"" -New-Item -Path $registryPath -Force | Out-Null -Set-ItemProperty -Path $registryPath -Name ""CanonicalName"" -Value ""{1380d028-a77f-4c12-96c7-ea276333f982}"" -Set-ItemProperty -Path $registryPath -Name ""Description"" -Value ""@shell32.dll,-31416"" -Set-ItemProperty -Path $registryPath -Name ""Icon"" -Value ""shell32.dll,-16814"" -Set-ItemProperty -Path $registryPath -Name ""MUIVerb"" -Value ""@shell32.dll,-31415"" -Set-ItemProperty -Path $registryPath -Name ""PaneID"" -Value ""{43abf98b-89b8-472d-b9ce-e69b8229f019}"" -Set-ItemProperty -Path $registryPath -Name ""PaneVisibleProperty"" -Value ""PreviewPaneSizer_Visible"" -Set-ItemProperty -Path $registryPath -Name ""PolicyID"" -Value ""{17067f8d-981b-42c5-98f8-5bc016d4b073}"" - -$registryPath = ""REGISTRY::HKEY_CLASSES_ROOT\LibraryFolder\background\shell\Windows.previewpane"" -New-Item -Path $registryPath -Force | Out-Null -Set-ItemProperty -Path $registryPath -Name ""CanonicalName"" -Value ""{1380d028-a77f-4c12-96c7-ea276333f982}"" -Set-ItemProperty -Path $registryPath -Name ""Description"" -Value ""@shell32.dll,-31416"" -Set-ItemProperty -Path $registryPath -Name ""Icon"" -Value ""shell32.dll,-16814"" -Set-ItemProperty -Path $registryPath -Name ""MUIVerb"" -Value ""@shell32.dll,-31415"" -Set-ItemProperty -Path $registryPath -Name ""PaneID"" -Value ""{43abf98b-89b8-472d-b9ce-e69b8229f019}"" -Set-ItemProperty -Path $registryPath -Name ""PaneVisibleProperty"" -Value ""PreviewPaneSizer_Visible"" -Set-ItemProperty -Path $registryPath -Name ""PolicyID"" -Value ""{17067f8d-981b-42c5-98f8-5bc016d4b073}"" - - "); - } - else - { - ps.AddScript(@" -# Disable Preview Pane -Remove-Item -Path ""REGISTRY::HKEY_CLASSES_ROOT\AllFilesystemObjects\shell\Windows.previewpane"" -Force -Confirm:$false -Remove-Item -Path ""REGISTRY::HKEY_CLASSES_ROOT\Directory\Background\shell\Windows.previewpane"" -Force -Confirm:$false -Remove-Item -Path ""REGISTRY::HKEY_CLASSES_ROOT\Drive\shell\Windows.previewpane"" -Force -Confirm:$false -Remove-Item -Path ""REGISTRY::HKEY_CLASSES_ROOT\LibraryFolder\background\shell\Windows.previewpane"" -Force -Confirm:$false - - "); - } - break; - case nameof(Settings.Default.printScrChecked): - if (isChecked) - { - ps.AddScript(@" -# Create SnapShot registry key and set its (Default) value -$registryPath = ""HKCU:\AppEvents\Schemes\Apps\.Default\SnapShot"" -if (-not (Test-Path $registryPath)) { - New-Item -Path $registryPath -Force | Out-Null -} -Set-ItemProperty -Path $registryPath -Name ""(Default)"" -Value """" + keyPath = @"Directory\Background\shell\Windows.previewpane"; + DeleteROOTRegistryKey(keyPath); -# Create .Current folder and set its (Default) key value -$currentFolderPath = ""HKCU:\AppEvents\Schemes\Apps\.Default\SnapShot\.Current"" -if (-not (Test-Path $currentFolderPath)) { - New-Item -Path $currentFolderPath -Force | Out-Null -} -Set-ItemProperty -Path $currentFolderPath -Name ""(Default)"" -Value ""C:\Windows\media\Windows Notify System Generic.wav"" + keyPath = @"Drive\shell\Windows.previewpane"; + DeleteROOTRegistryKey(keyPath); -# Create .Default folder and set its (Default) key value -$defaultFolderPath = ""HKCU:\AppEvents\Schemes\Apps\.Default\SnapShot\.Default"" -if (-not (Test-Path $defaultFolderPath)) { - New-Item -Path $defaultFolderPath -Force | Out-Null -} -Set-ItemProperty -Path $defaultFolderPath -Name ""(Default)"" -Value ""C:\Windows\media\Windows Notify System Generic.wav"" - -"); - } - else - { - ps.AddScript(@" -# Delete SnapShot folder without prompt -$registryPath = ""HKCU:\AppEvents\Schemes\Apps\.Default\SnapShot"" -if (Test-Path $registryPath) { - Remove-Item -Path $registryPath -Recurse -Force -Confirm:$false -} + keyPath = @"LibraryFolder\background\shell\Windows.previewpane"; + DeleteROOTRegistryKey(keyPath); + } + break; -"); - } - break; - } + case nameof(Settings.Default.printScrChecked): + keyPath = @"AppEvents\Schemes\Apps\.Default\SnapShot"; + if (isChecked) + { + SetHKCURegistryValue(keyPath, "(Default)", ""); + var currentFolderPath = $"{keyPath}\\.Current"; + SetHKCURegistryValue(currentFolderPath, "(Default)", @"C:\Windows\media\Windows Notify System Generic.wav"); - var output = ps.Invoke(); - if (ps.HadErrors) - { - Console.WriteLine("Script execution encountered errors:"); - foreach (var error in ps.Streams.Error) + var defaultFolderPath = $"{keyPath}\\.Default"; + SetHKCURegistryValue(defaultFolderPath, "(Default)", @"C:\Windows\media\Windows Notify System Generic.wav"); + } + else { - Console.WriteLine(error.ToString()); + DeleteHKCURegistryKey(keyPath); } - } - else - { - Console.WriteLine("Script executed successfully."); - // Handle successful execution here - } + break; + } + //using (PowerShell ps = PowerShell.Create()) + //{ + // switch (key) + // { + // case nameof(Settings.Default.contextMenuChecked): + // if (isChecked) + // { + // ps.AddScript(@" + //# Enable Classic Context Menu + //$regPath = ""HKCU:\Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32"" + + //# Check if the registry key exists + //if (-not (Test-Path $regPath)) { + // # Create the registry key if it doesn't exist + // New-Item -Path $regPath -Force | Out-Null + //} + + //# Set the default value + //Set-ItemProperty -Path $regPath -Name ""(Default)"" -Value """" + + //#RESTART EXPLORER!! + + // "); + + // } + // else + // { + // ps.AddScript(@" + //# Disable Classic Context Menu + //$regPath = ""REGISTRY::HKEY_CURRENT_USER\Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}"" + //Remove-Item -Path $regPath -Recurse -Force -ErrorAction SilentlyContinue -ErrorVariable RemoveError + + //if ($RemoveError) { + // Write-Host ""Error removing registry path: $regPath"" + // Write-Host $RemoveError + //} + //else { + // Write-Host ""Registry path removed successfully: $regPath"" + //} + + + //# RESTART EXPLORER!! + + // "); + + // } + // onRestartExplorer(); + // break; + // case nameof(Settings.Default.webSearchChecked): + // if (isChecked) + // { + // ps.AddScript(@" + //# Disable Web Search + //Set-ItemProperty -Path ""HKCU:\SOFTWARE\Policies\Microsoft\Windows\Explorer"" -Name ""DisableSearchBoxSuggestions"" -Value 1 + + //#SIGNOUT + + //"); + // } + // else + // { + // ps.AddScript(@" + //# Enable Web Search + //Remove-ItemProperty -Path ""HKCU:\SOFTWARE\Policies\Microsoft\Windows\Explorer"" -Name ""DisableSearchBoxSuggestions"" -ErrorAction SilentlyContinue + //#SIGNOUT + + //"); + // } + // onSignOut(); + // break; + // case nameof(Settings.Default.lockScreennChecked): + // if (isChecked) + // { + // ps.AddScript(@" + //#Disable Lock Screen + //$RegistryPath = ""HKLM:\SOFTWARE\Policies\Microsoft\Windows"" + //$PersonalizationKey = ""Personalization"" + //$NoLockScreenValueName = ""NoLockScreen"" + //$NoLockScreenValueData = 1 + + //# Create or open the Personalization key + //New-Item -Path $RegistryPath -Name $PersonalizationKey -Force | Out-Null + + //# Set the NoLockScreen value under the Personalization key + //Set-ItemProperty -Path ""$RegistryPath\$PersonalizationKey"" -Name $NoLockScreenValueName -Value $NoLockScreenValueData -Type DWORD -Force + + //"); + // } + // else + // { + // ps.AddScript(@" + //#Enable Lock Screen + //$RegistryPath = ""HKLM:\SOFTWARE\Policies\Microsoft\Windows"" + //$PersonalizationKey = ""Personalization"" + //$NoLockScreenValueName = ""NoLockScreen"" + //$NoLockScreenValueData = 0 + + //# Create or open the Personalization key + //New-Item -Path $RegistryPath -Name $PersonalizationKey -Force | Out-Null + + //# Set the NoLockScreen value under the Personalization key + //Set-ItemProperty -Path ""$RegistryPath\$PersonalizationKey"" -Name $NoLockScreenValueName -Value $NoLockScreenValueData -Type DWORD -Force + + //"); + // } + // break; + // case nameof(Settings.Default.compactViewChecked): + // if (isChecked) + // { + // ps.AddScript(@" + //#Enable Compact View + //$RegistryPath = ""HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced"" + //$UseCompactModeValueName = ""UseCompactMode"" + //$UseCompactModeValueData = 1 + + //# Check if the UseCompactMode value exists + //if (!(Test-Path ""$RegistryPath\$UseCompactModeValueName"")) { + // # Create the UseCompactMode value if it doesn't exist + // New-ItemProperty -Path $RegistryPath -Name $UseCompactModeValueName -PropertyType DWORD -Value $UseCompactModeValueData -Force | Out-Null + // Write-Host ""Value '$UseCompactModeValueName' created with value '$UseCompactModeValueData'."" + //} else { + // # Modify the existing UseCompactMode value + // Set-ItemProperty -Path $RegistryPath -Name $UseCompactModeValueName -Value $UseCompactModeValueData -Force + // Write-Host ""Value '$UseCompactModeValueName' modified to '$UseCompactModeValueData'."" + //} + // "); + // } + // else + // { + // ps.AddScript(@" + //#Disable Compact View + //$RegistryPath = ""HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced"" + //$UseCompactModeValueName = ""UseCompactMode"" + //$UseCompactModeValueData = 0 + + //# Check if the UseCompactMode value exists + //if (!(Test-Path ""$RegistryPath\$UseCompactModeValueName"")) { + // # Create the UseCompactMode value if it doesn't exist + // New-ItemProperty -Path $RegistryPath -Name $UseCompactModeValueName -PropertyType DWORD -Value $UseCompactModeValueData -Force | Out-Null + // Write-Host ""Value '$UseCompactModeValueName' created with value '$UseCompactModeValueData'."" + //} else { + // # Modify the existing UseCompactMode value + // Set-ItemProperty -Path $RegistryPath -Name $UseCompactModeValueName -Value $UseCompactModeValueData -Force + // Write-Host ""Value '$UseCompactModeValueName' modified to '$UseCompactModeValueData'."" + //} + + // "); + // } + // break; + // case nameof(Settings.Default.previewPaneChecked): + // if (isChecked) + // { + // ps.AddScript(@" + //# Enable Preview Pane + //$registryPath = ""AllFilesystemObjects\shell\Windows.previewpane"" + //New-Item -Path $registryPath -Force | Out-Null + //Set-ItemProperty -Path $registryPath -Name ""CanonicalName"" -Value ""{1380d028-a77f-4c12-96c7-ea276333f982}"" + //Set-ItemProperty -Path $registryPath -Name ""Description"" -Value ""@shell32.dll,-31416"" + //Set-ItemProperty -Path $registryPath -Name ""Icon"" -Value ""shell32.dll,-16814"" + //Set-ItemProperty -Path $registryPath -Name ""MUIVerb"" -Value ""@shell32.dll,-31415"" + //Set-ItemProperty -Path $registryPath -Name ""PaneID"" -Value ""{43abf98b-89b8-472d-b9ce-e69b8229f019}"" + //Set-ItemProperty -Path $registryPath -Name ""PaneVisibleProperty"" -Value ""PreviewPaneSizer_Visible"" + //Set-ItemProperty -Path $registryPath -Name ""PolicyID"" -Value ""{17067f8d-981b-42c5-98f8-5bc016d4b073}"" + + //$registryPath = ""Directory\Background\shell\Windows.previewpane"" + //New-Item -Path $registryPath -Force | Out-Null + //Set-ItemProperty -Path $registryPath -Name ""CanonicalName"" -Value ""{1380d028-a77f-4c12-96c7-ea276333f982}"" + //Set-ItemProperty -Path $registryPath -Name ""Description"" -Value ""@shell32.dll,-31416"" + //Set-ItemProperty -Path $registryPath -Name ""Icon"" -Value ""shell32.dll,-16814"" + //Set-ItemProperty -Path $registryPath -Name ""MUIVerb"" -Value ""@shell32.dll,-31415"" + //Set-ItemProperty -Path $registryPath -Name ""PaneID"" -Value ""{43abf98b-89b8-472d-b9ce-e69b8229f019}"" + //Set-ItemProperty -Path $registryPath -Name ""PaneVisibleProperty"" -Value ""PreviewPaneSizer_Visible"" + //Set-ItemProperty -Path $registryPath -Name ""PolicyID"" -Value ""{17067f8d-981b-42c5-98f8-5bc016d4b073}"" + + //$registryPath = ""Drive\shell\Windows.previewpane"" + //New-Item -Path $registryPath -Force | Out-Null + //Set-ItemProperty -Path $registryPath -Name ""CanonicalName"" -Value ""{1380d028-a77f-4c12-96c7-ea276333f982}"" + //Set-ItemProperty -Path $registryPath -Name ""Description"" -Value ""@shell32.dll,-31416"" + //Set-ItemProperty -Path $registryPath -Name ""Icon"" -Value ""shell32.dll,-16814"" + //Set-ItemProperty -Path $registryPath -Name ""MUIVerb"" -Value ""@shell32.dll,-31415"" + //Set-ItemProperty -Path $registryPath -Name ""PaneID"" -Value ""{43abf98b-89b8-472d-b9ce-e69b8229f019}"" + //Set-ItemProperty -Path $registryPath -Name ""PaneVisibleProperty"" -Value ""PreviewPaneSizer_Visible"" + //Set-ItemProperty -Path $registryPath -Name ""PolicyID"" -Value ""{17067f8d-981b-42c5-98f8-5bc016d4b073}"" + + //$registryPath = ""LibraryFolder\background\shell\Windows.previewpane"" + //New-Item -Path $registryPath -Force | Out-Null + //Set-ItemProperty -Path $registryPath -Name ""CanonicalName"" -Value ""{1380d028-a77f-4c12-96c7-ea276333f982}"" + //Set-ItemProperty -Path $registryPath -Name ""Description"" -Value ""@shell32.dll,-31416"" + //Set-ItemProperty -Path $registryPath -Name ""Icon"" -Value ""shell32.dll,-16814"" + //Set-ItemProperty -Path $registryPath -Name ""MUIVerb"" -Value ""@shell32.dll,-31415"" + //Set-ItemProperty -Path $registryPath -Name ""PaneID"" -Value ""{43abf98b-89b8-472d-b9ce-e69b8229f019}"" + //Set-ItemProperty -Path $registryPath -Name ""PaneVisibleProperty"" -Value ""PreviewPaneSizer_Visible"" + //Set-ItemProperty -Path $registryPath -Name ""PolicyID"" -Value ""{17067f8d-981b-42c5-98f8-5bc016d4b073}"" + + // "); + // } + // else + // { + // ps.AddScript(@" + //# Disable Preview Pane + //Remove-Item -Path ""AllFilesystemObjects\shell\Windows.previewpane"" -Force -Confirm:$false + //Remove-Item -Path ""Directory\Background\shell\Windows.previewpane"" -Force -Confirm:$false + //Remove-Item -Path ""Drive\shell\Windows.previewpane"" -Force -Confirm:$false + //Remove-Item -Path ""LibraryFolder\background\shell\Windows.previewpane"" -Force -Confirm:$false + + // "); + // } + // break; + // case nameof(Settings.Default.printScrChecked): + // if (isChecked) + // { + // ps.AddScript(@" + //# Create SnapShot registry key and set its (Default) value + //$registryPath = ""HKCU:\AppEvents\Schemes\Apps\.Default\SnapShot"" + //if (-not (Test-Path $registryPath)) { + // New-Item -Path $registryPath -Force | Out-Null + //} + //Set-ItemProperty -Path $registryPath -Name ""(Default)"" -Value """" + + //# Create .Current folder and set its (Default) key value + //$currentFolderPath = ""HKCU:\AppEvents\Schemes\Apps\.Default\SnapShot\.Current"" + //if (-not (Test-Path $currentFolderPath)) { + // New-Item -Path $currentFolderPath -Force | Out-Null + //} + //Set-ItemProperty -Path $currentFolderPath -Name ""(Default)"" -Value ""C:\Windows\media\Windows Notify System Generic.wav"" + + //# Create .Default folder and set its (Default) key value + //$defaultFolderPath = ""HKCU:\AppEvents\Schemes\Apps\.Default\SnapShot\.Default"" + //if (-not (Test-Path $defaultFolderPath)) { + // New-Item -Path $defaultFolderPath -Force | Out-Null + //} + //Set-ItemProperty -Path $defaultFolderPath -Name ""(Default)"" -Value ""C:\Windows\media\Windows Notify System Generic.wav"" + + //"); + // } + // else + // { + // ps.AddScript(@" + //# Delete SnapShot folder without prompt + //$registryPath = ""HKCU:\AppEvents\Schemes\Apps\.Default\SnapShot"" + //if (Test-Path $registryPath) { + // Remove-Item -Path $registryPath -Recurse -Force -Confirm:$false + //} + + //"); + // } + // break; + // } + + + // var output = ps.Invoke(); + // if (ps.HadErrors) + // { + // Console.WriteLine("Script execution encountered errors:"); + // foreach (var error in ps.Streams.Error) + // { + // Console.WriteLine(error.ToString()); + // } + // } + // else + // { + // Console.WriteLine("Script executed successfully."); + // // Handle successful execution here + // } + //} + } } - + private void previewDesc_Click(object sender, EventArgs e) { @@ -515,7 +737,7 @@ private void label1_MouseDown(object sender, MouseEventArgs e) private void appName_MouseUp(object sender, MouseEventArgs e) { - appName.ForeColor = Color.FromArgb(255,255,255); + appName.ForeColor = Color.FromArgb(255, 255, 255); } private void appName_MouseHover(object sender, EventArgs e) @@ -536,9 +758,9 @@ private void appName_Click(object sender, EventArgs e) private void lockScreenPanel_Click(object sender, EventArgs e) { - setPreview(new System.Drawing.Point(-5, -3), + setPreview(new System.Drawing.Point(-5, -3), new System.Drawing.Size(166, 95), - Resources.lockScreenImage, + Resources.lockScreenImage, "Lock Screen", "Disable the Windows 11 lock screen, directly access the login screen"); @@ -556,7 +778,7 @@ private void negativeBtn_Click_1(object sender, EventArgs e) { label2.Enabled = false; } - private void setDialogView(string desc, string btntext,int val) + private void setDialogView(string desc, string btntext, int val) { Properties.Settings.Default.dialogdesc = desc; Properties.Settings.Default.dialogPos = btntext; @@ -569,12 +791,12 @@ private void roundButton1_Click(object sender, EventArgs e) } private void onSignOut() { - setDialogView("Sign out for the changes to take the effect", "Sign Out",1); + setDialogView("Sign out for the changes to take the effect", "Sign Out", 1); dialog.ShowDialog(); } private void onRestartExplorer() { - setDialogView("Restart Explorer for the changes to take the effect", "Restart Explorer",0); + setDialogView("Restart Explorer for the changes to take the effect", "Restart Explorer", 0); dialog.ShowDialog(); } diff --git a/Win11Tweaker/Properties/AssemblyInfo.cs b/Win11Tweaker/Properties/AssemblyInfo.cs index fc24c91..d917f09 100644 --- a/Win11Tweaker/Properties/AssemblyInfo.cs +++ b/Win11Tweaker/Properties/AssemblyInfo.cs @@ -20,7 +20,7 @@ [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("b6d85876-2031-49d9-ad48-2302b3e7423b")] +[assembly: Guid("B70138D9-6036-4157-BD69-D6D1D2ABECEC")] // Version information for an assembly consists of the following four values: // diff --git a/Win11Tweaker/Win11Tweaker.csproj b/Win11Tweaker/Win11Tweaker.csproj index 78ecf25..40ef458 100644 --- a/Win11Tweaker/Win11Tweaker.csproj +++ b/Win11Tweaker/Win11Tweaker.csproj @@ -56,10 +56,11 @@ win11tweaker icon.ico - DE6B31DFC411E1563BD823EFFC747B8F12236A38 + 23A323565E1672A5C49B50A16F8B7AEA1B6FAB2F - Win11Tweaker_TemporaryKey.pfx + + false @@ -79,9 +80,6 @@ - - ..\packages\Microsoft.PowerShell.5.ReferenceAssemblies.1.1.0\lib\net4\System.Management.Automation.dll - diff --git a/Win11Tweaker/packages.config b/Win11Tweaker/packages.config index 53cba82..1d3a902 100644 --- a/Win11Tweaker/packages.config +++ b/Win11Tweaker/packages.config @@ -1,6 +1,4 @@  - - \ No newline at end of file