-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
437 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
[*.cs] | ||
|
||
# CS8602: Dereference of a possibly null reference. | ||
dotnet_diagnostic.CS8602.severity = none | ||
csharp_indent_labels = one_less_than_current | ||
csharp_using_directive_placement = outside_namespace:silent | ||
csharp_prefer_simple_using_statement = true:suggestion | ||
csharp_prefer_braces = true:silent | ||
csharp_style_namespace_declarations = block_scoped:silent | ||
csharp_style_prefer_method_group_conversion = true:silent | ||
csharp_style_prefer_top_level_statements = true:silent | ||
csharp_style_prefer_primary_constructors = true:suggestion | ||
csharp_style_expression_bodied_methods = false:silent | ||
csharp_style_expression_bodied_constructors = false:silent | ||
csharp_style_expression_bodied_operators = false:silent | ||
csharp_style_expression_bodied_properties = true:silent | ||
csharp_style_expression_bodied_indexers = true:silent | ||
csharp_style_expression_bodied_accessors = true:silent | ||
csharp_style_expression_bodied_lambdas = true:silent | ||
csharp_style_expression_bodied_local_functions = false:silent | ||
|
||
[*.{cs,vb}] | ||
dotnet_style_operator_placement_when_wrapping = beginning_of_line | ||
tab_width = 4 | ||
indent_size = 4 | ||
end_of_line = crlf | ||
dotnet_style_coalesce_expression = true:suggestion | ||
dotnet_style_null_propagation = true:suggestion | ||
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion | ||
dotnet_style_prefer_auto_properties = true:silent | ||
dotnet_style_object_initializer = true:suggestion | ||
dotnet_style_prefer_collection_expression = true:suggestion | ||
dotnet_style_collection_initializer = true:suggestion | ||
[*.{cs,vb}] | ||
#### Naming styles #### | ||
|
||
# Naming rules | ||
|
||
dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion | ||
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface | ||
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i | ||
|
||
dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion | ||
dotnet_naming_rule.types_should_be_pascal_case.symbols = types | ||
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case | ||
|
||
dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion | ||
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members | ||
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case | ||
|
||
# Symbol specifications | ||
|
||
dotnet_naming_symbols.interface.applicable_kinds = interface | ||
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected | ||
dotnet_naming_symbols.interface.required_modifiers = | ||
|
||
dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum | ||
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected | ||
dotnet_naming_symbols.types.required_modifiers = | ||
|
||
dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method | ||
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected | ||
dotnet_naming_symbols.non_field_members.required_modifiers = | ||
|
||
# Naming styles | ||
|
||
dotnet_naming_style.begins_with_i.required_prefix = I | ||
dotnet_naming_style.begins_with_i.required_suffix = | ||
dotnet_naming_style.begins_with_i.word_separator = | ||
dotnet_naming_style.begins_with_i.capitalization = pascal_case | ||
|
||
dotnet_naming_style.pascal_case.required_prefix = | ||
dotnet_naming_style.pascal_case.required_suffix = | ||
dotnet_naming_style.pascal_case.word_separator = | ||
dotnet_naming_style.pascal_case.capitalization = pascal_case | ||
|
||
dotnet_naming_style.pascal_case.required_prefix = | ||
dotnet_naming_style.pascal_case.required_suffix = | ||
dotnet_naming_style.pascal_case.word_separator = | ||
dotnet_naming_style.pascal_case.capitalization = pascal_case |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,216 @@ | ||
using System; | ||
using System.Diagnostics; | ||
|
||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
try | ||
{ | ||
Console.WriteLine("Do you want to enable or disable Windows Updates? (Type 'enable' or 'disable')"); | ||
string? userChoice = Console.ReadLine()?.ToLower(); | ||
|
||
if (userChoice == "disable") | ||
{ | ||
DisableWindowsUpdates(args); | ||
Console.WriteLine("Windows Update has been disabled."); | ||
} | ||
else if (userChoice == "enable") | ||
{ | ||
EnableWindowsUpdates(); | ||
Console.WriteLine("Windows Update has been enabled."); | ||
} | ||
else | ||
{ | ||
Console.WriteLine("Invalid choice. Please type 'enable' or 'disable'."); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine($"An error occurred: {ex.Message}"); | ||
} | ||
} | ||
|
||
static void DisableUpdateServices() | ||
{ | ||
var services = new[] { "wuauserv", "UsoSvc", "uhssvc", "WaaSMedicSvc" }; | ||
foreach (var service in services) | ||
{ | ||
ExecuteCommand($"net stop {service}"); | ||
ExecuteCommand($"sc config {service} start= disabled"); | ||
ExecuteCommand($"sc failure {service} reset= 0 actions= \"\""); | ||
} | ||
} | ||
|
||
static void BruteForceRenameServices() | ||
{ | ||
var services = new[] { "WaaSMedicSvc", "wuaueng" }; | ||
foreach (var service in services) | ||
{ | ||
var dllPath = Path.Combine(Environment.SystemDirectory, $"{service}.dll"); | ||
|
||
ExecuteCommand($"takeown /f \"{dllPath}\""); | ||
ExecuteCommand($"icacls \"{dllPath}\" /grant *S-1-1-0:F"); | ||
File.Move(dllPath, dllPath.Replace(".dll", "_BAK.dll")); | ||
ExecuteCommand($"icacls \"{dllPath.Replace(".dll", "_BAK.dll")}\" /setowner \"NT SERVICE\\TrustedInstaller\""); | ||
ExecuteCommand($"icacls \"{dllPath.Replace(".dll", "_BAK.dll")}\" /remove *S-1-1-0"); | ||
} | ||
} | ||
|
||
static void UpdateRegistry() | ||
{ | ||
ExecuteCommand("reg add \"HKLM\\SYSTEM\\CurrentControlSet\\Services\\WaaSMedicSvc\" /v Start /t REG_DWORD /d 4 /f"); | ||
ExecuteCommand("reg add \"HKLM\\SYSTEM\\CurrentControlSet\\Services\\WaaSMedicSvc\" /v FailureActions /t REG_BINARY /d 000000000000000000000000030000001400000000000000c0d4010000000000e09304000000000000000000 /f"); | ||
ExecuteCommand("reg add \"HKLM\\Software\\Policies\\Microsoft\\Windows\\WindowsUpdate\\AU\" /v NoAutoUpdate /t REG_DWORD /d 1 /f"); | ||
} | ||
|
||
static void DeleteDownloadedUpdates() | ||
{ | ||
var updatePath = @"c:\windows\softwaredistribution"; | ||
ExecuteCommand($"erase /f /s /q {updatePath}\\*.*"); | ||
ExecuteCommand($"rmdir /s /q {updatePath}"); | ||
} | ||
|
||
static void DisableScheduledTasks() | ||
{ | ||
var taskPaths = new[] | ||
{ | ||
@"\Microsoft\Windows\InstallService\*", | ||
@"\Microsoft\Windows\UpdateOrchestrator\*", | ||
@"\Microsoft\Windows\UpdateAssistant\*", | ||
@"\Microsoft\Windows\WaaSMedic\*", | ||
@"\Microsoft\Windows\WindowsUpdate\*", | ||
@"\Microsoft\WindowsUpdate\*" | ||
}; | ||
|
||
foreach (var taskPath in taskPaths) | ||
{ | ||
ExecuteCommand($"powershell -command \"Get-ScheduledTask -TaskPath '{taskPath}' | Disable-ScheduledTask\""); | ||
} | ||
} | ||
|
||
static void DisableWindowsUpdates(string[] args) | ||
{ | ||
DisableService("wuauserv"); | ||
DisableService("WaaSMedicSvc"); | ||
DisableService("UsoSvc"); | ||
|
||
ExecuteCommand("reg add \"HKEY_LOCAL_MACHINE\\SOFTWARE\\Policies\\Microsoft\\Windows\\WindowsUpdate\\AU\" /v NoAutoUpdate /t REG_DWORD /d 1 /f"); | ||
|
||
DisableUpdateServices(); | ||
BruteForceRenameServices(); | ||
UpdateRegistry(); | ||
DeleteDownloadedUpdates(); | ||
DisableScheduledTasks(); | ||
} | ||
|
||
static void EnableWindowsUpdates() | ||
{ | ||
EnableService("wuauserv"); | ||
EnableService("WaaSMedicSvc"); | ||
EnableService("UsoSvc"); | ||
|
||
EnableUpdateServices(); | ||
RestoreRenamedServices(); | ||
UpdateRegistrySecondly(); | ||
EnableScheduledTasks(); | ||
|
||
ExecuteCommand("reg add \"HKEY_LOCAL_MACHINE\\SOFTWARE\\Policies\\Microsoft\\Windows\\WindowsUpdate\\AU\" /v NoAutoUpdate /t REG_DWORD /d 0 /f"); | ||
} | ||
|
||
static void DisableService(string serviceName) | ||
{ | ||
if (IsServiceRunning(serviceName)) | ||
{ | ||
ExecuteCommand($"sc stop {serviceName}"); | ||
} | ||
else | ||
{ | ||
Console.WriteLine($"{serviceName} is already stopped!"); | ||
} | ||
ExecuteCommand($"sc config {serviceName} start= disabled"); | ||
} | ||
|
||
static void EnableService(string serviceName) | ||
{ | ||
ExecuteCommand($"sc config {serviceName} start= auto"); | ||
ExecuteCommand($"sc start {serviceName}"); | ||
} | ||
|
||
static bool IsServiceRunning(string serviceName) | ||
{ | ||
return ExecuteCommand($"sc query {serviceName}") == 0; | ||
} | ||
|
||
static bool TaskExists(string taskName) | ||
{ | ||
return ExecuteCommand($"schtasks /query /TN {taskName}") == 0; | ||
} | ||
static void EnableUpdateServices() | ||
{ | ||
ExecuteCommand("sc config wuauserv start= auto"); | ||
ExecuteCommand("sc config UsoSvc start= auto"); | ||
ExecuteCommand("sc config uhssvc start= delayed-auto"); | ||
} | ||
|
||
static void RestoreRenamedServices() | ||
{ | ||
var services = new[] { "WaaSMedicSvc", "wuaueng" }; | ||
foreach (var service in services) | ||
{ | ||
var dllPathBak = Path.Combine(Environment.SystemDirectory, $"{service}_BAK.dll"); | ||
var dllPath = Path.Combine(Environment.SystemDirectory, $"{service}.dll"); | ||
|
||
ExecuteCommand($"takeown /f \"{dllPathBak}\""); | ||
ExecuteCommand($"icacls \"{dllPathBak}\" /grant *S-1-1-0:F"); | ||
File.Move(dllPathBak, dllPath); | ||
ExecuteCommand($"icacls \"{dllPath}\" /setowner \"NT SERVICE\\TrustedInstaller\""); | ||
ExecuteCommand($"icacls \"{dllPath}\" /remove *S-1-1-0"); | ||
} | ||
} | ||
|
||
static void UpdateRegistrySecondly() | ||
{ | ||
ExecuteCommand("reg add \"HKLM\\SYSTEM\\CurrentControlSet\\Services\\WaaSMedicSvc\" /v Start /t REG_DWORD /d 3 /f"); | ||
ExecuteCommand("reg add \"HKLM\\SYSTEM\\CurrentControlSet\\Services\\WaaSMedicSvc\" /v FailureActions /t REG_BINARY /d 840300000000000000000000030000001400000001000000c0d4010001000000e09304000000000000000000 /f"); | ||
ExecuteCommand("reg delete \"HKLM\\Software\\Policies\\Microsoft\\Windows\\WindowsUpdate\\AU\" /v \"NoAutoUpdate\" /f"); | ||
} | ||
|
||
static void EnableScheduledTasks() | ||
{ | ||
var taskPaths = new[] | ||
{ | ||
@"\Microsoft\Windows\InstallService\*", | ||
@"\Microsoft\Windows\UpdateOrchestrator\*", | ||
@"\Microsoft\Windows\UpdateAssistant\*", | ||
@"\Microsoft\Windows\WaaSMedic\*", | ||
@"\Microsoft\Windows\WindowsUpdate\*", | ||
@"\Microsoft\WindowsUpdate\*" | ||
}; | ||
|
||
foreach (var taskPath in taskPaths) | ||
{ | ||
ExecuteCommand($"powershell -command \"Get-ScheduledTask -TaskPath '{taskPath}' | Enable-ScheduledTask\""); | ||
} | ||
} | ||
|
||
static int ExecuteCommand(string command) | ||
{ | ||
ProcessStartInfo processInfo = new ProcessStartInfo("cmd.exe", "/c " + command) | ||
{ | ||
CreateNoWindow = false, | ||
UseShellExecute = false, | ||
RedirectStandardOutput = true, | ||
RedirectStandardError = true | ||
}; | ||
|
||
using (Process process = Process.Start(processInfo)) | ||
{ | ||
process.OutputDataReceived += (sender, args) => Console.WriteLine(args.Data); | ||
process.BeginOutputReadLine(); | ||
process.BeginErrorReadLine(); | ||
process.WaitForExit(); | ||
return process.ExitCode; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,72 @@ | ||
# BuhByeWindowsUpdate | ||
A Console C# Project To Disable Windows Updates! | ||
|
||
A Console C# Program to enable and disable windows updates! | ||
|
||
## Features | ||
|
||
1. **Disable Windows Updates** | ||
- Stops and disables critical Windows Update services. | ||
- Renames service DLL files to prevent them from being loaded. | ||
- Updates the Windows registry to prevent automatic updates. | ||
- Deletes downloaded updates from the system. | ||
- Disables scheduled tasks related to Windows Updates. | ||
|
||
2. **Enable Windows Updates** | ||
- Starts and enables critical Windows Update services. | ||
- Restores any renamed service DLL files. | ||
- Updates the Windows registry to allow automatic updates. | ||
- Re-enables scheduled tasks related to Windows Updates. | ||
|
||
## How to Use | ||
|
||
### Running the Program | ||
|
||
**Open Command Prompt as Administrator** | ||
- To execute the commands that modify services and system settings, you need administrative privileges. | ||
|
||
### User Interaction | ||
When you run the program, it will prompt you with a choice: | ||
```cs | ||
Do you want to enable or disable Windows Updates? (Type 'enable' or 'disable') | ||
``` | ||
|
||
- **Type `disable`**: This will disable Windows Updates. The program will: | ||
- Stop and disable update services. | ||
- Rename related DLL files. | ||
- Update the registry to prevent automatic updates. | ||
- Delete downloaded updates. | ||
- Disable related scheduled tasks. | ||
|
||
- **Type `enable`**: This will enable Windows Updates. The program will: | ||
- Start and enable update services. | ||
- Restore renamed DLL files. | ||
- Update the registry to allow automatic updates. | ||
- Re-enable related scheduled tasks. | ||
|
||
If you type anything other than `enable` or `disable`, the program will prompt you to provide a valid choice. | ||
|
||
### Error Handling | ||
|
||
The program is designed to catch and display errors. If something goes wrong during execution, it will output the error message to help with troubleshooting. | ||
|
||
## Detailed Functionality | ||
|
||
### Disabling Windows Updates | ||
|
||
- **DisableUpdateServices()**: Stops and disables Windows Update services and sets their start mode to disabled. | ||
- **BruteForceRenameServices()**: Renames critical update-related DLL files to prevent them from being used. | ||
- **UpdateRegistry()**: Updates the Windows registry to prevent automatic updates. | ||
- **DeleteDownloadedUpdates()**: Deletes downloaded updates from the system. | ||
- **DisableScheduledTasks()**: Disables scheduled tasks related to Windows Updates. | ||
|
||
### Enabling Windows Updates | ||
|
||
- **EnableUpdateServices()**: Starts and enables Windows Update services and sets their start mode to auto. | ||
- **RestoreRenamedServices()**: Restores any renamed DLL files. | ||
- **UpdateRegistrySecondly()**: Updates the Windows registry to allow automatic updates. | ||
- **EnableScheduledTasks()**: Re-enables scheduled tasks related to Windows Updates. | ||
|
||
## Notes | ||
|
||
- Ensure that you have administrative privileges when running the program. | ||
- Use this tool with caution as it modifies system settings and services. |
Oops, something went wrong.