2
2
using GTweak . View ;
3
3
using Microsoft . Win32 ;
4
4
using System ;
5
+ using System . Collections . Generic ;
5
6
using System . ComponentModel ;
6
7
using System . Diagnostics ;
7
8
using System . IO ;
@@ -13,7 +14,14 @@ namespace GTweak.Utilities.Tweaks
13
14
{
14
15
internal sealed class ServicesTweaks : Firewall
15
16
{
16
- private static readonly string filesPathUpdate = Settings . PathSystemDisk + "Windows\\ System32\\ Tasks\\ Microsoft\\ Windows" ;
17
+ private static readonly SortedList < string , string > WinUpdatePaths = new SortedList < string , string >
18
+ {
19
+ [ "MoUso_New" ] = string . Concat ( Settings . PathSystemDisk , @"Windows\UUS\amd64\MoUsoCoreWorker.exe" ) ,
20
+ [ "MoUso_Old" ] = string . Concat ( Settings . PathSystemDisk , @"Windows\System32\MoUsoCoreWorker.exe" ) ,
21
+ [ "UpdateFolder" ] = string . Concat ( Settings . PathSystemDisk , @"Windows\System32\Tasks\Microsoft\Windows" ) ,
22
+ [ "RenMoUso_New" ] = string . Concat ( Settings . PathSystemDisk , @"Windows\UUS\amd64\BlockUpdate-GTweak.exe" ) ,
23
+ [ "RenMoUso_Old" ] = string . Concat ( Settings . PathSystemDisk , @"Windows\System32\BlockUpdate-GTweak.exe" )
24
+ } ;
17
25
18
26
internal void ViewServices ( ServicesView servicesV )
19
27
{
@@ -209,12 +217,12 @@ internal void ViewServices(ServicesView servicesV)
209
217
Registry . GetValue ( @"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\DoSvc" , "Start" , null ) == null ||
210
218
Registry . GetValue ( @"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\DoSvc" , "Start" , string . Empty ) . ToString ( ) != "4" ||
211
219
Registry . GetValue ( @"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\UsoSvc" , "Start" , null ) == null ||
212
- Registry . GetValue ( @"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\UsoSvc" , "Start" , string . Empty ) . ToString ( ) != "4" )
220
+ Registry . GetValue ( @"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\UsoSvc" , "Start" , string . Empty ) . ToString ( ) != "4" ||
221
+ ! File . Exists ( WinUpdatePaths [ "RenMoUso_New" ] ) & ! File . Exists ( WinUpdatePaths [ "RenMoUso_Old" ] ) )
213
222
servicesV . TglButton15 . StateNA = true ;
214
223
else
215
224
servicesV . TglButton15 . StateNA = false ;
216
225
217
-
218
226
if ( Registry . GetValue ( @"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\PolicyAgent" , "Start" , null ) == null ||
219
227
Registry . GetValue ( @"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\PolicyAgent" , "Start" , string . Empty ) . ToString ( ) != "4" ||
220
228
Registry . GetValue ( @"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\IKEEXT" , "Start" , null ) == null ||
@@ -598,6 +606,16 @@ static void StoreServices(bool isChoose)
598
606
break ;
599
607
case "TglButton15" :
600
608
BlockWindowsUpdate ( isChoose ) ;
609
+
610
+ string renameMoUsoNew = isChoose ? "rename " + WinUpdatePaths [ "MoUso_New" ] + " BlockUpdate-GTweak.exe" : "rename " + WinUpdatePaths [ "RenMoUso_New" ] + " MoUsoCoreWorker.exe" ;
611
+ string renameMoUsoOld = isChoose ? "rename " + WinUpdatePaths [ "MoUso_Old" ] + " BlockUpdate-GTweak.exe" : "rename " + WinUpdatePaths [ "RenMoUso_Old" ] + " MoUsoCoreWorker.exe" ;
612
+
613
+ using ( BackgroundWorker backgroundWorker = new BackgroundWorker ( ) )
614
+ {
615
+ backgroundWorker . DoWork += delegate { TrustedInstaller . CreateProcessAsTrustedInstaller ( Settings . PID , $ "cmd.exe /c { renameMoUsoNew } & { renameMoUsoOld } ") ; } ;
616
+ backgroundWorker . RunWorkerAsync ( ) ;
617
+ }
618
+
601
619
if ( isChoose )
602
620
{
603
621
RegistryHelp . Write ( Registry . LocalMachine , @"SYSTEM\CurrentControlSet\Services\wisvc" , "Start" , 4 , RegistryValueKind . DWord ) ;
@@ -626,7 +644,7 @@ static void StoreServices(bool isChoose)
626
644
}
627
645
using ( BackgroundWorker backgroundWorker = new BackgroundWorker ( ) )
628
646
{
629
- backgroundWorker . DoWork += ( s , e ) => { ChangeAccessUpdateFolder ( isChoose ) ; } ;
647
+ backgroundWorker . DoWork += delegate { ChangeAccessUpdateFolders ( isChoose ) ; } ;
630
648
backgroundWorker . RunWorkerAsync ( ) ;
631
649
}
632
650
break ;
@@ -828,7 +846,7 @@ static void StoreServices(bool isChoose)
828
846
}
829
847
}
830
848
831
- private async static void ChangeAccessUpdateFolder ( bool isDenyAccess )
849
+ private async static void ChangeAccessUpdateFolders ( bool isDenyAccess )
832
850
{
833
851
void SetFullAccess ( string path )
834
852
{
@@ -852,7 +870,7 @@ void ChangeStateTask()
852
870
"schtasks /change " + valueState + " /tn \" \\ Microsoft\\ Windows\\ UpdateOrchestrator\\ USO_UxBroker\" & " +
853
871
"schtasks /change " + valueState + " /tn \" \\ Microsoft\\ Windows\\ UpdateOrchestrator\\ UUS Failover Task\" & " +
854
872
"schtasks /change " + valueState + " /tn \" \\ Microsoft\\ Windows\\ WindowsUpdate\\ Refresh Group Policy Cache\" & " +
855
- "schtasks /change " + valueState + " /tn \" \\ Microsoft\\ Windows\\ WindowsUpdate\\ Scheduled Start\" " ) ;
873
+ "schtasks /change " + valueState + " /tn \" \\ Microsoft\\ Windows\\ WindowsUpdate\\ Scheduled Start\" " ) ;
856
874
}
857
875
858
876
try
@@ -873,12 +891,13 @@ void ChangeStateTask()
873
891
874
892
ChangeStateTask ( ) ;
875
893
894
+
876
895
await Task . Delay ( 1000 ) ;
877
896
878
897
Process . Start ( new ProcessStartInfo ( )
879
898
{
880
- Arguments = @"/c rd /s /q " + filesPathUpdate + "/(GTweak UpdateOrchestrator) & " +
881
- "rd /s /q " + filesPathUpdate + "/(GTweak WindowsUpdate)" ,
899
+ Arguments = @"/c rd /s /q " + WinUpdatePaths [ "UpdateFolder" ] + "/(GTweak UpdateOrchestrator) & " +
900
+ "rd /s /q " + WinUpdatePaths [ "UpdateFolder" ] + "/(GTweak WindowsUpdate)" ,
882
901
WindowStyle = ProcessWindowStyle . Hidden ,
883
902
CreateNoWindow = true ,
884
903
FileName = "cmd.exe"
@@ -887,18 +906,18 @@ void ChangeStateTask()
887
906
888
907
await Task . Delay ( 200 ) ;
889
908
890
- if ( Directory . Exists ( filesPathUpdate + "\\ UpdateOrchestrator" ) )
891
- Directory . Move ( filesPathUpdate + "\\ UpdateOrchestrator" , filesPathUpdate + "\\ (GTweak UpdateOrchestrator)" ) ;
892
- if ( Directory . Exists ( filesPathUpdate + "\\ WindowsUpdate" ) )
893
- Directory . Move ( filesPathUpdate + "\\ WindowsUpdate" , filesPathUpdate + "\\ (GTweak WindowsUpdate)" ) ;
909
+ if ( Directory . Exists ( WinUpdatePaths [ "UpdateFolder" ] + "\\ UpdateOrchestrator" ) )
910
+ Directory . Move ( WinUpdatePaths [ "UpdateFolder" ] + "\\ UpdateOrchestrator" , WinUpdatePaths [ "UpdateFolder" ] + "\\ (GTweak UpdateOrchestrator)" ) ;
911
+ if ( Directory . Exists ( WinUpdatePaths [ "UpdateFolder" ] + "\\ WindowsUpdate" ) )
912
+ Directory . Move ( WinUpdatePaths [ "UpdateFolder" ] + "\\ WindowsUpdate" , WinUpdatePaths [ "UpdateFolder" ] + "\\ (GTweak WindowsUpdate)" ) ;
894
913
}
895
914
else
896
915
{
897
916
898
- if ( Directory . Exists ( filesPathUpdate + "\\ (GTweak UpdateOrchestrator)" ) )
899
- Directory . Move ( filesPathUpdate + "\\ (GTweak UpdateOrchestrator)" , filesPathUpdate + "\\ UpdateOrchestrator" ) ;
900
- if ( Directory . Exists ( filesPathUpdate + "\\ (GTweak WindowsUpdate)" ) )
901
- Directory . Move ( filesPathUpdate + "\\ (GTweak WindowsUpdate)" , filesPathUpdate + "\\ WindowsUpdate" ) ;
917
+ if ( Directory . Exists ( WinUpdatePaths [ "UpdateFolder" ] + "\\ (GTweak UpdateOrchestrator)" ) )
918
+ Directory . Move ( WinUpdatePaths [ "UpdateFolder" ] + "\\ (GTweak UpdateOrchestrator)" , WinUpdatePaths [ "UpdateFolder" ] + "\\ UpdateOrchestrator" ) ;
919
+ if ( Directory . Exists ( WinUpdatePaths [ "UpdateFolder" ] + "\\ (GTweak WindowsUpdate)" ) )
920
+ Directory . Move ( WinUpdatePaths [ "UpdateFolder" ] + "\\ (GTweak WindowsUpdate)" , WinUpdatePaths [ "UpdateFolder" ] + "\\ WindowsUpdate" ) ;
902
921
903
922
await Task . Delay ( 500 ) ;
904
923
0 commit comments