Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 可以通过WMI设置远程桌面端口吗?_Windows_Wmi_Remote Desktop - Fatal编程技术网

Windows 可以通过WMI设置远程桌面端口吗?

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

我一直在尝试通过设置远程桌面监听的端口的方法。我知道我可以通过更改端口,但是是否可以通过WMI设置侦听端口,或者我必须编辑注册表?

可以。这是代码,引用了这个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