-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.ps1
71 lines (61 loc) · 3.56 KB
/
main.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
Add-Type -AssemblyName System.Windows.Forms
function CreateButton([string]$text, [int]$x, [int]$y, [int]$width, [int]$height) {
$button = New-Object System.Windows.Forms.Button
$button.Text, $button.Width, $button.Height, $button.Location = $text, $width, $height, (New-Object System.Drawing.Point($x, $y))
$button.Font, $button.ForeColor, $button.FlatStyle, $button.FlatAppearance.BorderSize, $button.FlatAppearance.MouseOverBackColor =
(New-Object System.Drawing.Font('Bahnschrift', 14)), [System.Drawing.Color]::White, [System.Windows.Forms.FlatStyle]::Flat, 0, [System.Drawing.Color]::Gray
$button
}
function SetService([string]$serviceName, [string]$startupType) {
Set-Service -Name $serviceName -StartupType $startupType -ErrorAction SilentlyContinue | Out-Null
if ($startupType -eq "Disabled") {
Stop-Service -Name $serviceName -ErrorAction SilentlyContinue | Out-Null
} else {
Start-Service -Name $serviceName -ErrorAction SilentlyContinue | Out-Null
}
}
function Log([string]$message, [string]$type) {
switch ($type) {
"Success" { Write-Host $message -ForegroundColor Green }
"Info" { Write-Host "$message..." -ForegroundColor Blue }
default { Write-Host $message }
}
}
$disableWindowsUpdate = CreateButton "Disable Windows Update" 50 56 250 60
$disableWindowsUpdate.Add_Click({
Log "Disabling Windows Update" "Info"
@("wuauserv", "WaaSMedicSvc", "UsoSvc") | ForEach-Object {
SetService $_ "Disabled"
}
Disable-ScheduledTask -TaskName "\Microsoft\Windows\WindowsUpdate\Scheduled Start" | Out-Null
if (!(Test-Path "HKLM:\Software\Microsoft\WindowsUpdate\UX\Settings")) {
New-Item -Path "HKLM:\Software\Microsoft\WindowsUpdate\UX\Settings" -Force | Out-Null
}
Set-ItemProperty -Path "HKLM:\Software\Microsoft\WindowsUpdate\UX\Settings" -Name "UxOption" -Type DWord -Value 1
Stop-Process -Name "MoUsoCoreWorker", "TiWorker" -Force -PassThru -ErrorAction SilentlyContinue | Out-Null
Set-ItemProperty -Path "HKLM:\SYSTEM\ControlSet001\Services\WaaSMedicSvc" -Name Start -Value 4
Log "Windows Update disabled successfully" "Success"
})
$enableWindowsUpdate = CreateButton "Enable Windows Update" 50 126 250 60
$enableWindowsUpdate.Add_Click({
Log "Enabling Windows Update" "Info"
@("wuauserv", "WaaSMedicSvc", "UsoSvc") | ForEach-Object {
SetService $_ "Automatic"
}
Enable-ScheduledTask -TaskName "\Microsoft\Windows\WindowsUpdate\Scheduled Start" | Out-Null
if (!(Test-Path "HKLM:\Software\Microsoft\WindowsUpdate\UX\Settings")) {
New-Item -Path "HKLM:\Software\Microsoft\WindowsUpdate\UX\Settings" -Force | Out-Null
}
Set-ItemProperty -Path "HKLM:\Software\Microsoft\WindowsUpdate\UX\Settings" -Name "UxOption" -Type DWord -Value 0
Set-ItemProperty -Path "HKLM:\SYSTEM\ControlSet001\Services\WaaSMedicSvc" -Name Start -Value 2
Log "Windows Update enabled successfully" "Success"
})
$form = New-Object System.Windows.Forms.Form
$form.Text = "Windows Update Control"
$form.MinimumSize, $form.MaximizeBox, $form.FormBorderStyle, $form.BackColor, $form.Font, $form.ForeColor =
(New-Object System.Drawing.Size(360, 250)), $false, [System.Windows.Forms.FormBorderStyle]::FixedDialog,
[System.Drawing.Color]::DimGray, (New-Object System.Drawing.Font('Bahnschrift', 10)), [System.Drawing.Color]::White
$form.Controls.Add($disableWindowsUpdate)
$form.Controls.Add($enableWindowsUpdate)
$form.Add_Shown({$form.Activate()})
$form.ShowDialog()