import winreg
def get_rdp_port():
try:
# 打开注册表键
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r"SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp", 0, winreg.KEY_READ)
# 读取端口值
port, _ = winreg.QueryValueEx(key, "PortNumber")
print(f"RDP port is: {
port}")
# 关闭注册表键
winreg.CloseKey(key)
except Exception as e:
print("Error:", e)
if __name__ == "__main__":
get_rdp_port()
文章评论