首页 > 编程 > VBScript > 正文

VBS 修改远程桌面端口号的代码

2019-10-26 18:05:52
字体:
来源:转载
供稿:网友
复制代码 代码如下:

'===========================================================================================
CheckOS ' 检查操作系统版本
CheckMeState ' 检查程序运行状态
main ' 执行主程序

Sub main()
Dim PortNumberOld, PortNumberNew
Set wso = CreateObject("WScript.Shell")

PortNumberOld = regKeyRead("HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/Terminal Server/WinStations/RDP-Tcp/PortNumber")
PortNumberNew = Trim( Inputbox( "请输入一个端口号:", "修改远程桌面端口", PortNumberOld ) )

If PortNumberNew = "" Then Exit Sub
If Not ( ( IsNumeric( PortNumberNew ) = True ) And ( PortNumberOld <> PortNumberNew ) And _
( PortNumberNew > 0 ) And ( PortNumberNew < 65535 ) ) Then
wso.popup "输入错误,请重试!", 5 , "错误:修改失败", 16+4096 ' 提示信息
Exit Sub
End If

wso.RegWrite "HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/Terminal Server/WinStations/RDP-Tcp/PortNumber", PortNumberNew, "REG_DWORD"
wso.RegWrite "HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/Terminal Server/Wds/rdpwd/Tds/tcp/PortNumber", PortNumberNew, "REG_DWORD"

PortNumberOld = regKeyRead("HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/Terminal Server/WinStations/RDP-Tcp/PortNumber")
If CLng( PortNumberOld ) = CLng( PortNumberNew ) Then
wso.popup "修改成功,请重启电脑!", 5 , "提示:修改成功", 64+4096
Else
wso.popup "修改失败,你可能没有权限!", 5 , "警告:修改失败", 48+4096
End If
Set wso = Nothing
End Sub

'===========================================================================================
'小函数
Function Exist( strPath )
'On Error Resume Next
Set fso = CreateObject("Scripting.FileSystemObject")
If ((fso.FolderExists( strPath )) Or (fso.FileExists( strPath ))) then
Exist = True
Else
Exist = False
End if
Set fso = Nothing
End Function
Sub Move( strSource, strDestination )
On Error Resume Next
If Exist( strSource ) Then
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(strSource)) Then fso.MoveFile strSource, strDestination
If (fso.FolderExists(strSource)) Then fso.MoveFolder strSource, strDestination
Set fso = Nothing
Else
WarningInfo "警告", "找不到 " & strSource & " 文件!", 2
End If
If Not Exist( strDestination ) Then WarningInfo "警告", "移动失败,无法移动 " & VbCrLf & strSource & " 至" & VbCrLf & strDestination, 2
End Sub
Sub RunHideNotWait( strCmd )
'On Error Resume Next
Set wso = CreateObject("WScript.Shell")
wso.Run strCmd, 0, False
Set wso = Nothing
End Sub
Function regKeyRead( strKey )
On Error Resume Next
Set wso = CreateObject("WScript.Shell")
regKeyRead = wso.RegRead( strKey ) 'strKey = "HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows/CurrentVersion/Run/DocTip"
Set wso = Nothing
End Function
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表