0

我一直在尝试通过远程桌面的WMI 管理类找到一种设置远程桌面侦听的端口的方法。我知道我可以通过注册表更改端口,但是可以通过 WMI 设置侦听端口还是必须编辑注册表?

4

1 回答 1

1

是的,它可以做到。这是代码,引用了这个 Microsoft链接这个。将 3389 替换为您要使用的新值:

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
于 2012-09-07T06:20:04.240 回答