找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 17535|回复: 0

[原创] VBS 修改远程桌面端口号

[复制链接]
发表于 2012-12-18 20:43:02 | 显示全部楼层 |阅读模式
仅有一个简单的功能——修改远程桌面端口。系统必须是XP。
或许应该发到新手区。
  1. '===========================================================================================
  2. CheckOS         ' 检查操作系统版本
  3. CheckMeState    ' 检查程序运行状态
  4. main            ' 执行主程序

  5. Sub main()
  6.         Dim PortNumberOld, PortNumberNew
  7.         Set wso = CreateObject("WScript.Shell")
  8.        
  9.         PortNumberOld = regKeyRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp\PortNumber")
  10.         PortNumberNew = Trim( Inputbox( "请输入一个端口号:", "修改远程桌面端口", PortNumberOld ) )
  11.        
  12.         If PortNumberNew = "" Then Exit Sub
  13.         If Not ( ( IsNumeric( PortNumberNew ) = True ) And ( PortNumberOld <> PortNumberNew ) And _
  14.                         ( PortNumberNew > 0 ) And ( PortNumberNew < 65535 ) ) Then
  15.                 wso.popup "输入错误,请重试!", 5 , "错误:修改失败", 16+4096    ' 提示信息
  16.                 Exit Sub
  17.         End If
  18.        
  19.         wso.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp\PortNumber", PortNumberNew, "REG_DWORD"
  20.         wso.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\Wds\rdpwd\Tds\tcp\PortNumber", PortNumberNew, "REG_DWORD"
  21.        
  22.         PortNumberOld = regKeyRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp\PortNumber")
  23.         If CLng( PortNumberOld ) = CLng( PortNumberNew ) Then
  24.                 wso.popup "修改成功,请重启电脑!", 5 , "提示:修改成功", 64+4096
  25.         Else
  26.                 wso.popup "修改失败,你可能没有权限!", 5 , "警告:修改失败", 48+4096
  27.         End If
  28.         Set wso = Nothing
  29. End Sub

  30. '===========================================================================================
  31. '小函数
  32. Function Exist( strPath )
  33.         'On Error Resume Next
  34.         Set fso = CreateObject("Scripting.FileSystemObject")
  35.         If ((fso.FolderExists( strPath )) Or (fso.FileExists( strPath ))) then
  36.                 Exist = True
  37.         Else
  38.                 Exist = False
  39.         End if
  40.         Set fso = Nothing
  41. End Function
  42. Sub Move( strSource, strDestination )
  43.         On Error Resume Next
  44.         If Exist( strSource ) Then
  45.                 Set fso = CreateObject("Scripting.FileSystemObject")
  46.                 If (fso.FileExists(strSource)) Then fso.MoveFile strSource, strDestination
  47.                 If (fso.FolderExists(strSource)) Then fso.MoveFolder strSource, strDestination
  48.                 Set fso = Nothing
  49.         Else
  50.                 WarningInfo "警告", "找不到 " & strSource & " 文件!", 2
  51.         End If
  52.         If Not Exist( strDestination ) Then WarningInfo "警告", "移动失败,无法移动 " & VbCrLf & strSource & " 至" & VbCrLf & strDestination, 2
  53. End Sub
  54. Sub RunHideNotWait( strCmd )
  55.         'On Error Resume Next
  56.         Set wso = CreateObject("WScript.Shell")
  57.         wso.Run strCmd, 0, False
  58.         Set wso = Nothing
  59. End Sub
  60. Function regKeyRead( strKey )
  61.         On Error Resume Next
  62.         Set wso = CreateObject("WScript.Shell")
  63.         regKeyRead = wso.RegRead( strKey )    'strKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\DocTip"
  64.         Set wso = Nothing
  65. End Function

  66. '===========================================================================================
  67. '是否重复运行
  68. Sub CheckMeState()
  69.         If IsRun( WScript.ScriptFullName ) Then
  70.                 Set wso = CreateObject("WScript.Shell")
  71.                 If wso.Popup("程序已运行,请不要重复运行本程序!" & VbCrLf & VbCrLf & _
  72.                                                         "退出已运行程序,请按“确定”,否则请按“取消”。(3秒后自动取消)" _
  73.                                                         , 3, "警告", 1) = 1 Then
  74.                         KillMeAllRun
  75.                 End If
  76.                 Set wso = Nothing
  77.                 'WarningInfo "警告:", "程序已运行,请不要重复运行本程序!!", 1
  78.                 WScript.Quit
  79.         End If
  80. End Sub
  81. ' 检测是否重复运行
  82. Function IsRun(appPath)
  83.         IsRun=False
  84.         For Each ps in GetObject("winmgmts:\\.\root\cimv2:win32_process").instances_
  85.                 'IF Lcase(ps.name)="mshta.exe" Then
  86.                 IF Lcase(ps.name)="wscript.exe" Then
  87.                         IF instr(Lcase(ps.CommandLine),Lcase(appPath)) Then i=i+1
  88.                 End IF
  89.         next
  90.         if i>1 then
  91.                 IsRun=True
  92.         end if
  93. End Function
  94. '终止自身
  95. Function KillMeAllRun()
  96.         Dim MeAllPid
  97.         Set pid = Getobject("winmgmts:\\.").InstancesOf("Win32_Process")
  98.         For Each ps In pid
  99.                 'if LCase(ps.name) = LCase("mshta.exe") then
  100.                 IF Lcase(ps.name)="wscript.exe" Or Lcase(ps.name)="cscript.exe"Then
  101.                         IF instr(Lcase(ps.CommandLine),Lcase(WScript.ScriptFullName)) Then MeAllPid = MeAllPid & "/PID " & ps.ProcessID & " "
  102.                 end if
  103.         next
  104.         RunHideNotWait "TASKKILL " & MeAllPid & " /F /T"
  105.         Set pid = Nothing
  106. End Function

  107. '===========================================================================================
  108. '检查操作系统版本
  109. Sub CheckOS()
  110.         Dim os_ver
  111.         os_ver = GetSystemVersion
  112.         If os_ver >= 60 Or os_ver <= 50 Then
  113.                 Msgbox "不支持该操作系统!    ", 48+4096, "警告"
  114.                 WScript.Quit    ' 退出程序
  115.         End If
  116. End Sub
  117. '取得操作系统版本
  118. Function GetSystemVersion()
  119.         Dim os_obj, os_version, os_version_arr
  120.         Set os_obj = GetObject("winmgmts:").InstancesOf("Win32_OperatingSystem")
  121.         For Each os_info In os_obj
  122.                 os_version = os_info.Version
  123.                 If os_version <> "" Then Exit For
  124.         Next
  125.         Set os_obj = Nothing
  126.         os_version_arr = Split( os_info.Version, ".")
  127.         GetSystemVersion = Cint( os_version_arr( 0 ) & os_version_arr( 1 ) )
  128. End Function
复制代码

评分

参与人数 1PB +5 收起 理由
batman + 5 感谢分享

查看全部评分

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-17 04:50 , Processed in 0.010473 second(s), 9 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表