Portable Tool for an Ideal Windows Setup
C# activatorbloatware-removalcsharpdebloatdebloaterdisable-servicesmonitoring-systemportableprivacy-toolsregistry-tweakssystem-tuningsystem-utilitytelemetrytweakerwindows-10windows-11windows-debloatwindows-defenderwindows-optimizationwindows-tweaks
-fix crash (dispose lock winkey) & re code
Greedekse6a1fcbea4d0
diff --git a/.Source/GTweak/Utilities/Helpers/DisablingWinKeys.cs b/.Source/GTweak/Utilities/Helpers/DisablingWinKeys.csindex 081cf609..1dcb16a5 100644--- a/.Source/GTweak/Utilities/Helpers/DisablingWinKeys.cs+++ b/.Source/GTweak/Utilities/Helpers/DisablingWinKeys.cs@@ -31,6 +31,8 @@ namespace GTweak.Utilities.Helpersinternal IntPtr ptrHook;internal LowLevelKeyboardProc objKeyboardProcess;+ internal DisablingWinKeys() => objKeyboardProcess = CaptureKey;+internal IntPtr CaptureKey(int nCode, IntPtr wp, IntPtr lp){if (nCode >= 0)@@ -47,4 +49,4 @@ namespace GTweak.Utilities.Helpersprivate bool HasAltModifier(int flags) => (flags & 0x20) == 0x20;}-}+}\ No newline at end of filediff --git a/.Source/GTweak/Utilities/Tweaks/WindowsLicense.cs b/.Source/GTweak/Utilities/Tweaks/WindowsLicense.csindex b34ad7d0..eede809c 100644--- a/.Source/GTweak/Utilities/Tweaks/WindowsLicense.cs+++ b/.Source/GTweak/Utilities/Tweaks/WindowsLicense.cs@@ -30,7 +30,7 @@ namespace GTweak.Utilities.Tweaks});}- internal static async void StartActivation()+ internal static async Task StartActivation(){string keyWinHWID = keysHWID.FirstOrDefault(k => IsVersionWindows(k.Key.pattern, k.Key.words)).Value ?? string.Empty;string keyWinKMS = keysKMS.FirstOrDefault(k => IsVersionWindows(k.Key.pattern, k.Key.words)).Value ?? string.Empty;@@ -43,55 +43,50 @@ namespace GTweak.Utilities.Tweaksnew ViewNotification().Show("", "warn", "activatewin_notification");- Process cmdProcess = new Process()+ static async Task RunCommandAsync(string arguments, int delay){- StartInfo = new ProcessStartInfo+ using Process cmdProcess = new Process{- FileName = "cmd.exe",- CreateNoWindow = true,- WindowStyle = ProcessWindowStyle.Hidden- }- };-- async Task RunCommand(string arguments, int delay)- {- cmdProcess.StartInfo.Arguments = arguments;+ StartInfo = new ProcessStartInfo+ {+ FileName = "cmd.exe",+ Arguments = arguments,+ CreateNoWindow = true,+ WindowStyle = ProcessWindowStyle.Hidden+ }+ };cmdProcess.Start();await Task.Delay(delay);}WaitingWindow waitingWindow = new WaitingWindow();+ waitingWindow.Show();- using (cmdProcess)+ try{- waitingWindow.Show();-if (SystemDiagnostics.IsWindowsVersion[10])- await RunCommand("/c assoc .vbs=VBSFile", 500);+ await RunCommandAsync("/c assoc .vbs=VBSFile", 500);- await RunCommand($"/c slmgr.vbs //b /ipk {keyWinHWID}", 4000);+ await RunCommandAsync($"/c slmgr.vbs //b /ipk {keyWinHWID}", 4000);- CommandExecutor.RunCommand($@"/c del /f /q {StoragePaths.SystemDisk}ProgramData\Microsoft\Windows\ClipSVC\GenuineTicket\*.xml & del /f /q {StoragePaths.SystemDisk}ProgramData\Microsoft\Windows\ClipSVC\Install\Migration\*.xml");+ CommandExecutor.RunCommand($@"/c del /f /q {StoragePaths.SystemDisk}ProgramData\Microsoft\Windows\ClipSVC\GenuineTicket\*.xml");string originalGeo = RegistryHelp.GetValue(@"HKEY_CURRENT_USER\Control Panel\International\Geo", "Name", string.Empty);RegistryHelp.Write(Registry.CurrentUser, @"Control Panel\International\Geo", "Name", "US", RegistryValueKind.String);foreach (string service in new string[] { "ClipSVC", "wlidsvc", "sppsvc", "KeyIso", "LicenseManager", "Winmgmt" })CommandExecutor.RunCommand($"sc config {service} start= auto && sc start {service}");+await Task.Delay(3000);- try- {- XDocument xmlDoc = XDocument.Parse(Properties.Resources.Tickets);- XElement foundTicket = xmlDoc.Descendants("Ticket").FirstOrDefault(t => t.Element("product") != null && t.Element("product").Value.IndexOf(RegistryHelp.GetValue(@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ProductOptions", "OSProductPfn", string.Empty), StringComparison.OrdinalIgnoreCase) >= 0);- foundTicket ??= xmlDoc.Descendants("Ticket").FirstOrDefault(t => t.Element("product") != null && t.Element("product").Value == "KMS");- XDocument genuineXml = XDocument.Parse(foundTicket.Element("content")?.Value.Trim());- genuineXml.Save(Path.Combine(StoragePaths.SystemDisk, "ProgramData", "Microsoft", "Windows", "ClipSVC", "GenuineTicket", "GenuineTicket.xml"));- await Task.Delay(3000);- CommandExecutor.RunCommand("clipup -v -o", true);- }- catch (Exception ex) { Debug.WriteLine(ex.Message); }+ XDocument xmlDoc = XDocument.Parse(Properties.Resources.Tickets);+ XElement foundTicket = xmlDoc.Descendants("Ticket").FirstOrDefault(t => t.Element("product") != null && t.Element("product").Value.IndexOf(RegistryHelp.GetValue(@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ProductOptions", "OSProductPfn", string.Empty), StringComparison.OrdinalIgnoreCase) >= 0);+ foundTicket ??= xmlDoc.Descendants("Ticket").FirstOrDefault(t => t.Element("product") != null && t.Element("product").Value == "KMS");+ XDocument genuineXml = XDocument.Parse(foundTicket.Element("content")?.Value.Trim());+ genuineXml.Save(Path.Combine(StoragePaths.SystemDisk, "ProgramData", "Microsoft", "Windows", "ClipSVC", "GenuineTicket", "GenuineTicket.xml"));+ await Task.Delay(3000);+ CommandExecutor.RunCommand("clipup -v -o", true);await Task.Delay(1000);- await RunCommand("/c slmgr.vbs //b /ato", 3500);+ await RunCommandAsync("/c slmgr.vbs //b /ato", 3500);RegistryHelp.Write(Registry.CurrentUser, @"Control Panel\International\Geo", "Name", originalGeo, RegistryValueKind.String);@@ -106,22 +101,24 @@ namespace GTweak.Utilities.Tweaks}else{- using (cmdProcess)- {- await RunCommand($"/c slmgr.vbs //b /ipk {keysKMS}", 4000);- await RunCommand("/c slmgr.vbs //b /skms kms.digiboy.ir", 7000);- await RunCommand("/c slmgr.vbs //b /ato", 3500);+ await RunCommandAsync($"/c slmgr.vbs //b /ipk {keysKMS}", 4000);+ await RunCommandAsync("/c slmgr.vbs //b /skms kms.digiboy.ir", 7000);+ await RunCommandAsync("/c slmgr.vbs //b /ato", 3500);- new WindowsLicense().LicenseStatus();+ new WindowsLicense().LicenseStatus();- await Task.Delay(2000);+ await Task.Delay(2000);- waitingWindow.Close();+ waitingWindow.Close();- new ViewNotification(300).Show(IsWindowsActivated ? "restart" : "", "warn", IsWindowsActivated ? "successactivate_notification" : "notsuccessactivate_notification");- }+ new ViewNotification(300).Show(IsWindowsActivated ? "restart" : "", "warn", IsWindowsActivated ? "successactivate_notification" : "notsuccessactivate_notification");}}+ catch+ {+ waitingWindow.Close();+ new ViewNotification(300).Show("", "warn", "notsuccessactivate_notification");+ }}}}diff --git a/.Source/GTweak/View/MoreView.xaml.cs b/.Source/GTweak/View/MoreView.xaml.csindex 4b2c2c3c..8fff614e 100644--- a/.Source/GTweak/View/MoreView.xaml.cs+++ b/.Source/GTweak/View/MoreView.xaml.cs@@ -16,14 +16,14 @@ namespace GTweak.ViewInitializeComponent();}- private void BtnLicenseWindows_ClickButton(object sender, EventArgs e)+ private async void BtnLicenseWindows_ClickButton(object sender, EventArgs e){if (WindowsLicense.IsWindowsActivated)new ViewNotification().Show("", "info", "readyactivate_notification");else{if (SystemDiagnostics.CurrentConnection == SystemDiagnostics.ConnectionStatus.Available || SystemDiagnostics.CurrentConnection == SystemDiagnostics.ConnectionStatus.Block)- WindowsLicense.StartActivation();+ await WindowsLicense.StartActivation();elsenew ViewNotification().Show("", "warn", "networklicense_notification");}diff --git a/.Source/GTweak/View/PakagesView.xaml.cs b/.Source/GTweak/View/PakagesView.xaml.csindex 0e1b9848..863924b7 100644--- a/.Source/GTweak/View/PakagesView.xaml.cs+++ b/.Source/GTweak/View/PakagesView.xaml.cs@@ -63,21 +63,16 @@ namespace GTweak.View{case MouseButtonState.Pressed when Equals(pakageImage.Source, FindResource("A_DI_" + packageName)):{+ UninstallingPakages.HandleAvailabilityStatus(packageName, true);+ UpdateViewStatePakages();+timer.Stop();BackgroundQueue backgroundQueue = new BackgroundQueue();- await backgroundQueue.QueueTask(delegate { UninstallingPakages.DeletingPackage(packageName); });-await backgroundQueue.QueueTask(async delegate{try{- await Dispatcher.InvokeAsync(() =>- {- UninstallingPakages.HandleAvailabilityStatus(packageName, true);- UpdateViewStatePakages();- });-await UninstallingPakages.DeletingPackage(packageName);await Task.Delay(3000);@@ -100,6 +95,9 @@ namespace GTweak.Viewcase MouseButtonState.Pressed when Equals(pakageImage.Source, FindResource("DA_DI_" + packageName)) && packageName == "OneDrive":{+ UninstallingPakages.HandleAvailabilityStatus(packageName, true);+ UpdateViewStatePakages();+timer.Stop();new ViewNotification().Show("", "info", "onedrive_notification");@@ -109,12 +107,6 @@ namespace GTweak.View{try{- await Dispatcher.InvokeAsync(() =>- {- UninstallingPakages.HandleAvailabilityStatus(packageName, true);- UpdateViewStatePakages();- });-await UninstallingPakages.ResetOneDrive();await Dispatcher.InvokeAsync(() =>