使用VBS禁用、啟動(dòng)USB存儲設(shè)備
來源:易賢網(wǎng) 閱讀:689 次 日期:2014-12-16 15:51:05
溫馨提示:易賢網(wǎng)小編為您整理了“使用VBS禁用、啟動(dòng)USB存儲設(shè)備”,方便廣大網(wǎng)友查閱!

USB存儲設(shè)備控制 By Yu2n

XP系統(tǒng)測試通過,需要管理員權(quán)限。

在下次插拔設(shè)備時(shí)生效,無須重啟。

?123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 'USB_Stock_Block.vbs '=========================================================================================== CheckOS ' 檢查操作系統(tǒng)版本 CheckMeState ' 檢查程序運(yùn)行狀態(tài) main ' 執(zhí)行主程序 '=========================================================================================== '主函數(shù) Sub main() Dim wso, windir, EnableUSB Set wso = CreateObject("WScript.Shell") Set objNetwork = CreateObject("wscript.network") strComputer = objNetwork.ComputerName If wso.Popup(VbCrLf & "禁用 USB 存儲設(shè)備,請按“確定”"& VbCrLf & _ VbCrLf & "啟用 USB 存儲設(shè)備,請按“取消” (6秒后自動(dòng)取消)" _ , 6, "USB 存儲設(shè)備控制 - 主菜單", 48+4096+1) = 1 Then EnableUSB = 0 Else EnableUSB = 1 End If If Exist( "C:\windows\system32\cmd.exe" ) Then windir = "windows" If Exist( "C:\winnt\system32\cmd.exe" ) Then windir = "winnt" If EnableUSB = 1 Then wso.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\StorageDevicePolicies\WriteProtect","1","REG_DWORD" '禁止寫入 wso.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\USBSTOR\Start","3","REG_DWORD" '啟用USBStor Move "C:\" & windir & "\inf\usbstor.pnf_" , "C:\" & windir & "\inf\usbstor.pnf" Move "C:\" & windir & "\inf\usbstor.inf_" , "C:\" & windir & "\inf\usbstor.inf" Move "C:\" & windir & "\system32\drivers\usbstor.sys_" , "C:\" & windir & "\system32\drivers\usbstor.sys" If (Not Exist( "C:\" & windir & "\inf\usbstor.pnf_" )) And (regKeyRead( "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\USBSTOR\Start" ) = 3 ) Then wso.Popup VbCrLf & "啟用 USB 存儲設(shè)備成功?!   ?, 5, "USB 存儲設(shè)備控制 - 操作完成", 64+4096 Else wso.Popup VbCrLf & "啟用 USB 存儲設(shè)備失敗?!   ?, 5, "USB 存儲設(shè)備控制 - 操作完成", 16+4096 End If Else wso.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\StorageDevicePolicies\WriteProtect","1","REG_DWORD" '禁止寫入 wso.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\USBSTOR\Start","4","REG_DWORD" '禁用用USBStor Move "C:\" & windir & "\inf\usbstor.pnf" , "C:\" & windir & "\inf\usbstor.pnf_" Move "C:\" & windir & "\inf\usbstor.inf" , "C:\" & windir & "\inf\usbstor.inf_" Move "C:\" & windir & "\system32\drivers\usbstor.sys" , "C:\" & windir & "\system32\drivers\usbstor.sys_" If (Not Exist( "C:\" & windir & "\inf\usbstor.pnf" )) And (regKeyRead( "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\USBSTOR\Start" ) = 4 ) Then wso.Popup VbCrLf & "禁用 USB 存儲設(shè)備成功?!   ?, 5, "USB 存儲設(shè)備控制 - 操作完成", 64+4096 Else wso.Popup VbCrLf & "禁用 USB 存儲設(shè)備失敗?!   ?, 5, "USB 存儲設(shè)備控制 - 操作完成", 16+4096 End If End if Set wso = NothingEnd Sub '=========================================================================================== '小函數(shù) 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 = NothingEnd FunctionSub 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 "警告", "移動(dòng)失敗,無法移動(dòng) " & VbCrLf & strSource & " 至" & VbCrLf & strDestination, 2 End SubFunction regKeyRead( strKey ) Set wso = CreateObject("WScript.Shell") regKeyRead = wso.RegRead( strKey ) 'strKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\DocTip" Set wso = NothingEnd Function '=========================================================================================== '是否重復(fù)運(yùn)行 Sub CheckMeState() If IsRun( WScript.ScriptFullName ) Then Set wso = CreateObject("WScript.Shell") If wso.Popup("程序已運(yùn)行,請不要重復(fù)運(yùn)行本程序!" & VbCrLf & VbCrLf & _ "退出已運(yùn)行程序,請按“確定”,否則請按“取消”。(3秒后自動(dòng)取消)" _ , 3, "警告", 1) = 1 Then KillMeAllRun End If Set wso = Nothing 'WarningInfo "警告:", "程序已運(yùn)行,請不要重復(fù)運(yùn)行本程序!!", 1 WScript.Quit End IfEnd Sub' 檢測是否重復(fù)運(yùn)行 Function IsRun(appPath) IsRun=False For Each ps in GetObject("winmgmts:\\.\root\cimv2:win32_process").instances_ 'IF Lcase(ps.name)="mshta.exe" Then IF Lcase(ps.name)="wscript.exe" Then IF instr(Lcase(ps.CommandLine),Lcase(appPath)) Then i=i+1 End IF next if i>1 then IsRun=True end if End Function'終止自身 Function KillMeAllRun() Dim MeAllPid Set pid = Getobject("winmgmts:\\.").InstancesOf("Win32_Process") For Each ps In pid 'if LCase(ps.name) = LCase("mshta.exe") then IF Lcase(ps.name)="wscript.exe" Or Lcase(ps.name)="cscript.exe"Then IF instr(Lcase(ps.CommandLine),Lcase(WScript.ScriptFullName)) Then MeAllPid = MeAllPid & "/PID " & ps.ProcessID & " " end if next Set wso = CreateObject("WScript.Shell") wso.Run "TASKKILL " & MeAllPid & " /F /T", 0, False Set wso = Nothing Set pid = NothingEnd Function '=========================================================================================== '檢查操作系統(tǒng)版本 Sub CheckOS() Dim os_ver os_ver = GetSystemVersion If os_ver >= 60 Or os_ver <= 50 Then Msgbox "不支持該操作系統(tǒng)!    ", 48+4096, "警告" WScript.Quit ' 退出程序 End IfEnd Sub'取得操作系統(tǒng)版本 Function GetSystemVersion() Dim os_obj, os_version, os_version_arr Set os_obj = GetObject("winmgmts:").InstancesOf("Win32_OperatingSystem") For Each os_info In os_obj os_version = os_info.Version If os_version <> "" Then Exit For Next Set os_obj = Nothing os_version_arr = Split( os_info.Version, ".") GetSystemVersion = Cint( os_version_arr( 0 ) & os_version_arr( 1 ) ) End Function

更多信息請查看IT技術(shù)專欄

更多信息請查看腳本欄目
易賢網(wǎng)手機(jī)網(wǎng)站地址:使用VBS禁用、啟動(dòng)USB存儲設(shè)備
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

2025國考·省考課程試聽報(bào)名

  • 報(bào)班類型
  • 姓名
  • 手機(jī)號
  • 驗(yàn)證碼
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 加入群交流 | 手機(jī)站點(diǎn) | 投訴建議
工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號
云南網(wǎng)警備案專用圖標(biāo)
聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號:hfpxwx
咨詢QQ:526150442(9:00—18:00)版權(quán)所有:易賢網(wǎng)
云南網(wǎng)警報(bào)警專用圖標(biāo)