-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrdp_windows.py
27 lines (24 loc) · 1.02 KB
/
rdp_windows.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
import winreg
def enable_remote_connections():
try:
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r'SYSTEM\CurrentControlSet\Control\Terminal Server', 0, winreg.KEY_WRITE)
winreg.SetValueEx(key, 'fDenyTSConnections', 0, winreg.REG_DWORD, 0)
print("Remote connections enabled successfully.")
except Exception as e:
print(f"Failed to enable remote connections: {str(e)}")
finally:
if key:
winreg.CloseKey(key)
def disable_remote_connections():
try:
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r'SYSTEM\CurrentControlSet\Control\Terminal Server', 0, winreg.KEY_WRITE)
winreg.SetValueEx(key, 'fDenyTSConnections', 0, winreg.REG_DWORD, 1)
print("Remote connections disabled successfully.")
except Exception as e:
print(f"Failed to disable remote connections: {str(e)}")
finally:
if key:
winreg.CloseKey(key)
# Example usage:
#enable_remote_connections()
disable_remote_connections()