国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > VBScript > 正文

使用VBS禁用、啟動USB存儲設備

2020-06-26 18:40:24
字體:
來源:轉載
供稿:網友

這篇文章主要介紹了使用VBS禁用、啟動USB存儲設備,需要的朋友可以參考下

USB存儲設備控制 By Yu2n

XP系統測試通過,需要管理員權限。

在下次插拔設備時生效,無須重啟。

  1. 'USB_Stock_Block.vbs 
  2. '=========================================================================================== 
  3. CheckOS ' 檢查操作系統版本 
  4. CheckMeState ' 檢查程序運行狀態 
  5. main ' 執行主程序 
  6.  
  7. '=========================================================================================== 
  8. '主函數 
  9. Sub main() 
  10. Dim wso, windir, EnableUSB 
  11. Set wso = CreateObject("WScript.Shell"
  12. Set objNetwork = CreateObject("wscript.network"
  13. strComputer = objNetwork.ComputerName 
  14.  
  15. If wso.Popup(VbCrLf & "禁用 USB 存儲設備,請按“確定”"& VbCrLf & _ 
  16. VbCrLf & "啟用 USB 存儲設備,請按“取消” (6秒后自動取消)" _ 
  17. , 6, "USB 存儲設備控制 - 主菜單", 48+4096+1) = 1 Then 
  18. EnableUSB = 0 
  19. Else 
  20. EnableUSB = 1 
  21. End If 
  22.  
  23. If Exist( "C:/windows/system32/cmd.exe" ) Then windir = "windows" 
  24. If Exist( "C:/winnt/system32/cmd.exe" ) Then windir = "winnt" 
  25.  
  26. If EnableUSB = 1 Then 
  27. wso.RegWrite "HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/StorageDevicePolicies/WriteProtect","1","REG_DWORD" '禁止寫入 
  28. wso.RegWrite "HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/USBSTOR/Start","3","REG_DWORD" '啟用USBStor 
  29.  
  30. Move "C:/" & windir & "/inf/usbstor.pnf_" , "C:/" & windir & "/inf/usbstor.pnf" 
  31. Move "C:/" & windir & "/inf/usbstor.inf_" , "C:/" & windir & "/inf/usbstor.inf" 
  32. Move "C:/" & windir & "/system32/drivers/usbstor.sys_" , "C:/" & windir & "/system32/drivers/usbstor.sys" 
  33.  
  34. If (Not Exist( "C:/" & windir & "/inf/usbstor.pnf_" )) And (regKeyRead( "HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/USBSTOR/Start" ) = 3 ) Then 
  35. wso.Popup VbCrLf & "啟用 USB 存儲設備成功。    ", 5, "USB 存儲設備控制 - 操作完成", 64+4096 
  36. Else 
  37. wso.Popup VbCrLf & "啟用 USB 存儲設備失敗。    ", 5, "USB 存儲設備控制 - 操作完成", 16+4096 
  38. End If 
  39. Else 
  40. wso.RegWrite "HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/StorageDevicePolicies/WriteProtect","1","REG_DWORD" '禁止寫入 
  41. wso.RegWrite "HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/USBSTOR/Start","4","REG_DWORD" '禁用用USBStor 
  42.  
  43. Move "C:/" & windir & "/inf/usbstor.pnf" , "C:/" & windir & "/inf/usbstor.pnf_" 
  44. Move "C:/" & windir & "/inf/usbstor.inf" , "C:/" & windir & "/inf/usbstor.inf_" 
  45. Move "C:/" & windir & "/system32/drivers/usbstor.sys" , "C:/" & windir & "/system32/drivers/usbstor.sys_" 
  46.  
  47. If (Not Exist( "C:/" & windir & "/inf/usbstor.pnf" )) And (regKeyRead( "HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/USBSTOR/Start" ) = 4 ) Then 
  48. wso.Popup VbCrLf & "禁用 USB 存儲設備成功。    ", 5, "USB 存儲設備控制 - 操作完成", 64+4096 
  49. Else 
  50. wso.Popup VbCrLf & "禁用 USB 存儲設備失敗。    ", 5, "USB 存儲設備控制 - 操作完成", 16+4096 
  51. End If 
  52. End if 
  53.  
  54. Set wso = Nothing 
  55. End Sub 
  56.  
  57. '=========================================================================================== 
  58. '小函數 
  59. Function Exist( strPath ) 
  60. 'On Error Resume Next 
  61. Set fso = CreateObject("Scripting.FileSystemObject"
  62. If ((fso.FolderExists( strPath )) Or (fso.FileExists( strPath ))) then 
  63. Exist = True 
  64. Else 
  65. Exist = False 
  66. End if 
  67. Set fso = Nothing 
  68. End Function 
  69. Sub Move( strSource, strDestination ) 
  70. On Error Resume Next 
  71. If Exist( strSource ) Then 
  72. Set fso = CreateObject("Scripting.FileSystemObject"
  73. If (fso.FileExists(strSource)) Then fso.MoveFile strSource, strDestination 
  74. If (fso.FolderExists(strSource)) Then fso.MoveFolder strSource, strDestination 
  75. Set fso = Nothing 
  76. Else 
  77. WarningInfo "警告""找不到 " & strSource & " 文件!", 2 
  78. End If 
  79. If Not Exist( strDestination ) Then WarningInfo "警告""移動失敗,無法移動 " & VbCrLf & strSource & " 至" & VbCrLf & strDestination, 2 
  80. End Sub 
  81. Function regKeyRead( strKey ) 
  82. Set wso = CreateObject("WScript.Shell"
  83. regKeyRead = wso.RegRead( strKey ) 'strKey = "HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows/CurrentVersion/Run/DocTip" 
  84. Set wso = Nothing 
  85. End Function 
  86.  
  87. '=========================================================================================== 
  88. '是否重復運行 
  89. Sub CheckMeState() 
  90. If IsRun( WScript.ScriptFullName ) Then 
  91. Set wso = CreateObject("WScript.Shell"
  92. If wso.Popup("程序已運行,請不要重復運行本程序!" & VbCrLf & VbCrLf & _ 
  93. "退出已運行程序,請按“確定”,否則請按“取消”。(3秒后自動取消)" _ 
  94. , 3, "警告", 1) = 1 Then 
  95. KillMeAllRun 
  96. End If 
  97. Set wso = Nothing 
  98. 'WarningInfo "警告:", "程序已運行,請不要重復運行本程序!!", 1 
  99. WScript.Quit 
  100. End If 
  101. End Sub 
  102. ' 檢測是否重復運行 
  103. Function IsRun(appPath) 
  104. IsRun=False 
  105. For Each ps in GetObject("winmgmts://./root/cimv2:win32_process").instances_ 
  106. 'IF Lcase(ps.name)="mshta.exe" Then 
  107. IF Lcase(ps.name)="wscript.exe" Then 
  108. IF instr(Lcase(ps.CommandLine),Lcase(appPath)) Then i=i+1 
  109. End IF 
  110. next 
  111. if i>1 then 
  112. IsRun=True 
  113. end if 
  114. End Function 
  115. '終止自身 
  116. Function KillMeAllRun() 
  117. Dim MeAllPid 
  118. Set pid = Getobject("winmgmts://.").InstancesOf("Win32_Process"
  119. For Each ps In pid 
  120. 'if LCase(ps.name) = LCase("mshta.exe") then 
  121. IF Lcase(ps.name)="wscript.exe" Or Lcase(ps.name)="cscript.exe"Then 
  122. IF instr(Lcase(ps.CommandLine),Lcase(WScript.ScriptFullName)) Then MeAllPid = MeAllPid & "/PID " & ps.ProcessID & " " 
  123. end if 
  124. next 
  125. Set wso = CreateObject("WScript.Shell"
  126. wso.Run "TASKKILL " & MeAllPid & " /F /T", 0, False 
  127. Set wso = Nothing 
  128. Set pid = Nothing 
  129. End Function 
  130.  
  131. '=========================================================================================== 
  132. '檢查操作系統版本 
  133. Sub CheckOS() 
  134. Dim os_ver 
  135. os_ver = GetSystemVersion 
  136. If os_ver >= 60 Or os_ver <= 50 Then 
  137. Msgbox "不支持該操作系統!    ", 48+4096, "警告" 
  138. WScript.Quit ' 退出程序 
  139. End If 
  140. End Sub 
  141. '取得操作系統版本 
  142. Function GetSystemVersion() 
  143. Dim os_obj, os_version, os_version_arr 
  144. Set os_obj = GetObject("winmgmts:").InstancesOf("Win32_OperatingSystem"
  145. For Each os_info In os_obj 
  146. os_version = os_info.Version 
  147. If os_version <> "" Then Exit For 
  148. Next 
  149. Set os_obj = Nothing 
  150. os_version_arr = Split( os_info.Version, "."
  151. GetSystemVersion = Cint( os_version_arr( 0 ) & os_version_arr( 1 ) ) 
  152. End Function 
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 安新县| 楚雄市| 赤峰市| 苍南县| 深水埗区| 平陆县| 大洼县| 阳高县| 隆化县| 庄河市| 抚州市| 涿州市| 沂南县| 清徐县| 云阳县| 江油市| 成都市| 集贤县| 泸州市| 霍城县| 弥勒县| 东城区| 独山县| 五峰| 南木林县| 论坛| 通许县| 马尔康县| 江阴市| 古浪县| 白河县| 清涧县| 西和县| 临泉县| 南投市| 酒泉市| 武安市| 铜梁县| 义乌市| 安图县| 阳新县|