第七课:sql server 常用操作远程桌面语句

1、是否开启远程桌面

    1:表示关闭
    0:表示开启
    1
    EXEC master..xp_regread 'HKEY_LOCAL_MACHINE',
    2
    'SYSTEM\CurrentControlSet\Control\Terminal Server',
    3
    'fDenyTSConnections'
    Copied!

2、读取远程桌面端口

1
EXEC master..xp_regread 'HKEY_LOCAL_MACHINE',
2
'SYSTEM\CurrentControlSet\Control\TerminalServer\WinStations\RDP-Tcp',
3
'PortNumber'
Copied!

3、开启远程桌面

1
EXEC master.dbo.xp_regwrite'HKEY_LOCAL_MACHINE',
2
'SYSTEM\CurrentControlSet\Control\TerminalServer',
3
'fDenyTSConnections','REG_DWORD',0;
Copied!
reg 文件开启远程桌面:
1
Windows Registry Editor Version 5.00HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TerminalServer]
2
"fDenyTSConnections"=dword:00000000[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TerminalServer\WinStations\RDP-Tcp]
3
"PortNumber"=dword:00000d3d
Copied!
//// 保存 micropoor.reg,并执行 regedit /s micropoor.reg
注:如果第一次开启远程桌面,部分需要配置防火墙规则允许远程端口。
1
netsh advfirewall firewall add rule name="Remote Desktop" protocol=TCP
2
dir=in localport=3389 action=allow
Copied!

4、关闭远程桌面

1
EXEC master.dbo.xp_regwrite'HKEY_LOCAL_MACHINE',
2
'SYSTEM\CurrentControlSet\Control\TerminalServer',
3
'fDenyTSConnections','REG_DWORD',1;
Copied!
--By Micropoor
Last modified 2yr ago