[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

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

仅有一个简单的功能——修改远程桌面端口。系统必须是XP。
或许应该发到新手区。
  1. '===========================================================================================
  2. CheckOS         ' 检查操作系统版本
  3. CheckMeState    ' 检查程序运行状态
  4. main            ' 执行主程序
  5. Sub main()
  6. Dim PortNumberOld, PortNumberNew
  7. Set wso = CreateObject("WScript.Shell")
  8. PortNumberOld = regKeyRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp\PortNumber")
  9. PortNumberNew = Trim( Inputbox( "请输入一个端口号:", "修改远程桌面端口", PortNumberOld ) )
  10. If PortNumberNew = "" Then Exit Sub
  11. If Not ( ( IsNumeric( PortNumberNew ) = True ) And ( PortNumberOld <> PortNumberNew ) And _
  12. ( PortNumberNew > 0 ) And ( PortNumberNew < 65535 ) ) Then
  13. wso.popup "输入错误,请重试!", 5 , "错误:修改失败", 16+4096    ' 提示信息
  14. Exit Sub
  15. End If
  16. wso.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp\PortNumber", PortNumberNew, "REG_DWORD"
  17. wso.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\Wds\rdpwd\Tds\tcp\PortNumber", PortNumberNew, "REG_DWORD"
  18. PortNumberOld = regKeyRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp\PortNumber")
  19. If CLng( PortNumberOld ) = CLng( PortNumberNew ) Then
  20. wso.popup "修改成功,请重启电脑!", 5 , "提示:修改成功", 64+4096
  21. Else
  22. wso.popup "修改失败,你可能没有权限!", 5 , "警告:修改失败", 48+4096
  23. End If
  24. Set wso = Nothing
  25. End Sub
  26. '===========================================================================================
  27. '小函数
  28. Function Exist( strPath )
  29. 'On Error Resume Next
  30. Set fso = CreateObject("Scripting.FileSystemObject")
  31. If ((fso.FolderExists( strPath )) Or (fso.FileExists( strPath ))) then
  32. Exist = True
  33. Else
  34. Exist = False
  35. End if
  36. Set fso = Nothing
  37. End Function
  38. Sub Move( strSource, strDestination )
  39. On Error Resume Next
  40. If Exist( strSource ) Then
  41. Set fso = CreateObject("Scripting.FileSystemObject")
  42. If (fso.FileExists(strSource)) Then fso.MoveFile strSource, strDestination
  43. If (fso.FolderExists(strSource)) Then fso.MoveFolder strSource, strDestination
  44. Set fso = Nothing
  45. Else
  46. WarningInfo "警告", "找不到 " & strSource & " 文件!", 2
  47. End If
  48. If Not Exist( strDestination ) Then WarningInfo "警告", "移动失败,无法移动 " & VbCrLf & strSource & " 至" & VbCrLf & strDestination, 2
  49. End Sub
  50. Sub RunHideNotWait( strCmd )
  51. 'On Error Resume Next
  52. Set wso = CreateObject("WScript.Shell")
  53. wso.Run strCmd, 0, False
  54. Set wso = Nothing
  55. End Sub
  56. Function regKeyRead( strKey )
  57. On Error Resume Next
  58. Set wso = CreateObject("WScript.Shell")
  59. regKeyRead = wso.RegRead( strKey )    'strKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\DocTip"
  60. Set wso = Nothing
  61. End Function
  62. '===========================================================================================
  63. '是否重复运行
  64. Sub CheckMeState()
  65. If IsRun( WScript.ScriptFullName ) Then
  66. Set wso = CreateObject("WScript.Shell")
  67. If wso.Popup("程序已运行,请不要重复运行本程序!" & VbCrLf & VbCrLf & _
  68. "退出已运行程序,请按“确定”,否则请按“取消”。(3秒后自动取消)" _
  69. , 3, "警告", 1) = 1 Then
  70. KillMeAllRun
  71. End If
  72. Set wso = Nothing
  73. 'WarningInfo "警告:", "程序已运行,请不要重复运行本程序!!", 1
  74. WScript.Quit
  75. End If
  76. End Sub
  77. ' 检测是否重复运行
  78. Function IsRun(appPath)
  79. IsRun=False
  80. For Each ps in GetObject("winmgmts:\\.\root\cimv2:win32_process").instances_
  81. 'IF Lcase(ps.name)="mshta.exe" Then
  82. IF Lcase(ps.name)="wscript.exe" Then
  83. IF instr(Lcase(ps.CommandLine),Lcase(appPath)) Then i=i+1
  84. End IF
  85. next
  86. if i>1 then
  87. IsRun=True
  88. end if
  89. End Function
  90. '终止自身
  91. Function KillMeAllRun()
  92. Dim MeAllPid
  93. Set pid = Getobject("winmgmts:\\.").InstancesOf("Win32_Process")
  94. For Each ps In pid
  95. 'if LCase(ps.name) = LCase("mshta.exe") then
  96. IF Lcase(ps.name)="wscript.exe" Or Lcase(ps.name)="cscript.exe"Then
  97. IF instr(Lcase(ps.CommandLine),Lcase(WScript.ScriptFullName)) Then MeAllPid = MeAllPid & "/PID " & ps.ProcessID & " "
  98. end if
  99. next
  100. RunHideNotWait "TASKKILL " & MeAllPid & " /F /T"
  101. Set pid = Nothing
  102. End Function
  103. '===========================================================================================
  104. '检查操作系统版本
  105. Sub CheckOS()
  106. Dim os_ver
  107. os_ver = GetSystemVersion
  108. If os_ver >= 60 Or os_ver <= 50 Then
  109. Msgbox "不支持该操作系统!    ", 48+4096, "警告"
  110. WScript.Quit    ' 退出程序
  111. End If
  112. End Sub
  113. '取得操作系统版本
  114. Function GetSystemVersion()
  115. Dim os_obj, os_version, os_version_arr
  116. Set os_obj = GetObject("winmgmts:").InstancesOf("Win32_OperatingSystem")
  117. For Each os_info In os_obj
  118. os_version = os_info.Version
  119. If os_version <> "" Then Exit For
  120. Next
  121. Set os_obj = Nothing
  122. os_version_arr = Split( os_info.Version, ".")
  123. GetSystemVersion = Cint( os_version_arr( 0 ) & os_version_arr( 1 ) )
  124. End Function
复制代码
1

评分人数

『千江有水千江月』千江有水,月映千江;万里无云,万里青天。    http://yu2n.qiniudn.com/

返回列表