-
Notifications
You must be signed in to change notification settings - Fork 0
/
setMonitors.py
105 lines (88 loc) · 3.9 KB
/
setMonitors.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
#needs to be run as admin to read from graphics configuration
import winreg as wrg
errorFound = False
monitors = []
location = wrg.HKEY_LOCAL_MACHINE
baseLocation = r"SYSTEM\\CurrentControlSet\\Control\\GraphicsDrivers\\Configuration"
regKey = wrg.OpenKeyEx(location, baseLocation)
monitorKey = wrg.OpenKeyEx(location, baseLocation + r"\\" + wrg.EnumKey(regKey, 0))
# check monitor amount
monitorCount = 0
try:
while (True):
print(wrg.EnumKey(regKey, monitorCount))
monitors.append(wrg.EnumKey(regKey, monitorCount))
monitorCount += 1
print(monitorCount)
if (monitorCount >= 2):
errorFound = True
except:
print ("all keys")
# check/set values
if (errorFound != True):
try:
currentKey = wrg.OpenKeyEx(location, baseLocation + r"\\" + wrg.EnumKey(regKey, 0) + "\\00\\00", 0, wrg.KEY_ALL_ACCESS)
if (wrg.QueryValueEx(currentKey, "Rotation")[0] != 1):
print (wrg.QueryValueEx(currentKey, "Rotation"))
wrg.SetValueEx(currentKey, "Rotation", 0, wrg.REG_DWORD, 1)
except Exception as f:
print (f)
try:
currentKey = wrg.OpenKeyEx(location, baseLocation + r"\\" + wrg.EnumKey(regKey, 0) + "\\01\\00", 0, wrg.KEY_ALL_ACCESS)
if (wrg.QueryValueEx(currentKey, "Rotation")[0] != 2):
print (wrg.QueryValueEx(currentKey, "Rotation"))
wrg.SetValueEx(currentKey, "Rotation", 0, wrg.REG_DWORD, 2)
except Exception as f:
print (f)
try:
currentKey = wrg.OpenKeyEx(location, baseLocation + r"\\" + wrg.EnumKey(regKey, 0) + "\\01", 0, wrg.KEY_ALL_ACCESS)
if (wrg.QueryValueEx(currentKey, "Position.cx")[0] != 4294966396):
print (wrg.QueryValueEx(currentKey, "Position.cx"))
wrg.SetValueEx(currentKey, "Position.cx", 0, wrg.REG_DWORD, 4294966396)
except Exception as f:
print (f)
try:
currentKey = wrg.OpenKeyEx(location, baseLocation + r"\\" + wrg.EnumKey(regKey, 0) + "\\01", 0, wrg.KEY_ALL_ACCESS)
if (wrg.QueryValueEx(currentKey, "Position.cy")[0] != 4294967052):
print (wrg.QueryValueEx(currentKey, "Position.cy"))
wrg.SetValueEx(currentKey, "Position.cy", 0, wrg.REG_DWORD, 4294967052)
except Exception as f:
print (f)
if (errorFound):
print ("Error")
try:
print (monitorCount)
while (monitorCount > 0):
monitorKey = wrg.OpenKeyEx(location, baseLocation + r"\\" + wrg.EnumKey(regKey, 0), 0, wrg.KEY_ALL_ACCESS)
try:
print ("Subkeys deletion")
try:
currentKey = wrg.OpenKeyEx(location, baseLocation + r"\\" + wrg.EnumKey(regKey, 0) + "\\00\\00", 0, wrg.KEY_ALL_ACCESS)
wrg.DeleteKey(currentKey, "")
except Exception as f:
print (f)
try:
currentKey = wrg.OpenKeyEx(location, baseLocation + r"\\" + wrg.EnumKey(regKey, 0) + "\\01\\00", 0, wrg.KEY_ALL_ACCESS)
wrg.DeleteKey(currentKey, "")
except Exception as f:
print (f)
try:
currentKey = wrg.OpenKeyEx(location, baseLocation + r"\\" + wrg.EnumKey(regKey, 0) + "\\00", 0, wrg.KEY_ALL_ACCESS)
wrg.DeleteKey(currentKey, "")
except Exception as f:
print (f)
try:
currentKey = wrg.OpenKeyEx(location, baseLocation + r"\\" + wrg.EnumKey(regKey, 0) + "\\01", 0, wrg.KEY_ALL_ACCESS)
wrg.DeleteKey(currentKey, "")
except Exception as f:
print (f)
except Exception as e:
print (e)
monitorCount -= 1
wrg.DeleteKey(monitorKey, "")
except Exception as e:
print (e)
print ("all keys deleted")
print ("no error detected")
regKey.Close()
monitorKey.Close()