Windows 可以通过WMI设置远程桌面端口吗?
我一直在尝试通过设置远程桌面监听的端口的方法。我知道我可以通过更改端口,但是是否可以通过WMI设置侦听端口,或者我必须编辑注册表?可以。这是代码,引用了这个Microsoft和一个。将3389替换为要使用的新值:Windows 可以通过WMI设置远程桌面端口吗?,windows,wmi,remote-desktop,Windows,Wmi,Remote Desktop,我一直在尝试通过设置远程桌面监听的端口的方法。我知道我可以通过更改端口,但是是否可以通过WMI设置侦听端口,或者我必须编辑注册表?可以。这是代码,引用了这个Microsoft和一个。将3389替换为要使用的新值: const HKEY_LOCAL_MACHINE = &H80000002 strComputer = "." 'Set StdOut = WScript.StdOut Set oReg=GetObject( _ "winmgmts:{impersonationLeve
const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
'Set StdOut = WScript.StdOut
Set oReg=GetObject( _
"winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")
strKeyPath = "SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp"
strValueName = "PortNumber"
' Display old value
oReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue
WScript.Echo "Old RDP value=" & dwValue
' Set new value
dwValue= 3389
oReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue
If Err = 0 Then
oReg.GetDWORDValue _
HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue
WScript.Echo "New RDP Value =" & dwValue
Else
WScript.Echo "Error in creating key" & _
" and DWORD value = " & Err.Number
End If