This repository was archived by the owner on Mar 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBanWindows11.py
116 lines (86 loc) · 4.17 KB
/
BanWindows11.py
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import ctypes, sys
import winreg
import platform
if platform.system() != "Windows":
print('[ERROR] This script can only run on Windows.')
exit()
# Function to check if the script is running with administrator privileges
def is_admin():
try:
return ctypes.windll.shell32.IsUserAnAdmin()
except:
return False
if is_admin() == False:
print('[ERROR] This script requires administrator privileges. Starting with administrator privileges...')
ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, " ".join(sys.argv), None, 1)
exit()
try:
# Open the key
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Policies\\Microsoft\\Windows\\WindowsUpdate")
# Get the value of the "ProductVersion" registry key and assign it to product_version variable
product_version = winreg.QueryValueEx(key, "ProductVersion")[0]
# Get the value of the "TargetReleaseVersion" registry key and assign it to target_release_version variable
target_release_version = winreg.QueryValueEx(key, "TargetReleaseVersion")[0]
# Get the value of the "TargetReleaseVersionInfo" registry key annd assign it to target_release_version_info variable
target_release_version_info = winreg.QueryValueEx(key, "TargetReleaseVersionInfo")[0]
# Close the key
winreg.CloseKey(key)
except WindowsError:
print('[WARNING] Registry keys not found. Creating...')
# Create new key
key = winreg.CreateKey(winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Policies\\Microsoft\\Windows\\WindowsUpdate")
# Set the value of the "ProductVersion" registry key
winreg.SetValueEx(key, "ProductVersion", 0, winreg.REG_SZ, "Windows 10")
# Set the value of the "TargetReleaseVersion" registry key
winreg.SetValueEx(key, "TargetReleaseVersion", 0, winreg.REG_DWORD, "1")
# Set the value of the "TargetReleaseVersionInfo" registry key
winreg.SetValueEx(key, "TargetReleaseVersionInfo", 0, winreg.REG_SZ, "22H2")
# Close the key
winreg.CloseKey(key)
print('[INFO] Registry keys created.')
# Function to print the actions
def printActions():
print('BanWindows11 - Python Port')
print('-------------------------------')
print('Please select an action to perform:')
print('1) Disable Windows 11 Upgrade')
print('2) Enable Windows 11 Upgrade')
# Get user input
action = input('\n> ')
# Check if the user input is valid
try:
int(action)
except:
print('Please enter a valid action. Example: 1')
printActions()
if int(action) == 1:
target_release = input('Please type the Target Release (Example: 22H2): ')
# Open the key
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Policies\\Microsoft\\Windows\\WindowsUpdate")
# Set the value of the "ProductVersion" registry key
winreg.SetValueEx(key, "ProductVersion", 0, winreg.REG_SZ, "Windows 10")
# Set the value of the "TargetReleaseVersion" registry key
winreg.SetValueEx(key, "TargetReleaseVersion", 0, winreg.REG_DWORD, "1")
# Set the value of the "TargetReleaseVersionInfo" registry key
winreg.SetValueEx(key, "TargetReleaseVersionInfo", 0, winreg.REG_SZ, target_release)
# Close the key
winreg.CloseKey(key)
# Wait for user to press enter to exit
input('Press Enter to exit...')
elif int(action) == 2:
# Open the key
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Policies\\Microsoft\\Windows\\WindowsUpdate")
# Set the value of the "ProductVersion" registry key
winreg.SetValueEx(key, "ProductVersion", 0, winreg.REG_SZ, "Windows 10")
# Set the value of the "TargetReleaseVersion" registry key
winreg.SetValueEx(key, "TargetReleaseVersion", 0, winreg.REG_DWORD, "0")
# Set the value of the "TargetReleaseVersionInfo" registry key
winreg.SetValueEx(key, "TargetReleaseVersionInfo", 0, winreg.REG_SZ, "22H2")
# Close the key
winreg.CloseKey(key)
# Wait for user to press enter to exit
input('Press Enter to exit...')
else:
print('Please enter a valid action. Example: 1')
printActions()
printActions()