Disabling and starting USB storage devices using the VBS _VBS

Source: Internet
Author: User

USB storage Device Control by yu2n

XP system test passed and requires administrator privileges.

The next time you plug the device into effect, you do not need to reboot.

' Usb_stock_block.vbs ' ========================================================================================= = = Checkos ' Check operating system version checkmestate ' Check program run status Main ' execute main program ' =================================================== ======================================== ' main function Sub main () Dim WSO, windir, Enableusb Set WSO = CreateObject ("Wscrip
        
    T.shell ") Set objnetwork = CreateObject (" Wscript.Network ") StrComputer = Objnetwork.computername If WSO. Popup (VbCrLf & "Disable USB storage device, press" OK "& VbCrLf & _ VbCrLf &" Enable USB storage device, press "Cancel" (automatically cancel after 6 seconds) " _, 6, "USB storage Device Control-Main Menu", 48+4096+1) = 1 Then enableusb = 0 Else enableusb = 1 En D 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 "is forbidden to write to WSO.
        
        RegWrite "Hkey_local_machine\system\currentcontrolset\services\usbstor\start", "3", "REG_DWORD" ' Enable 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 &A mp "\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 & "Enable USB storage device success. ", 5," USB storage device Control-operation complete ", 64+4096 Else WSO.    Popup VbCrLf & "Enable USB storage device failed. ", 5," USB storage device Control-operation complete ", 16+4096 end If Else WSO. RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\CURRENTCONTROLSET\CONTROL\STORAGEDEVICEPOLICIES\WRIteprotect "," 1 "," REG_DWORD "is forbidden to write to WSO.
        
        RegWrite "Hkey_local_machine\system\currentcontrolset\services\usbstor\start", "4", "REG_DWORD" ' disabled with 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 & Amp "\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 & Disable USB storage device success. ", 5," USB storage device Control-operation complete ", 64+4096 Else WSO.    Popup VbCrLf & Disable USB storage device failed. ", 5," USB storage device Control-operation complete ", 16+4096 End If the Set WSO = Nothing The Sub ' ==================== ======================================================================= ' small function 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 = no end Func tion Sub Move (strsource, strdestination) on Error Resume Next If Exist (strsource) Then Set fso = creat Eobject ("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 "Warning", "Can't Find" & strsource & Amp File ", 2-if If not Exist (strdestination) Then warninginfo" Warning "," move failed, cannot move "& VbCrLf & strsource & "To" & VbCrLf & Strdestination, 2 end Sub Function regkeyread (strkey) Set WSO = CreateObject ("Wscript.Shell" ) RegKeyRead = WSO. RegRead (strkey) ' strkey = ' hkey_local_machine\software\microsoft\windows\currentversion\run\doctip ' Set WSO = Nothi ng end Function ' =========================================================================================== '
        Do you want to run the Sub checkmestate () if Isrun (wscript.scriptfullname) Then Set WSO = CreateObject ("Wscript.Shell") repeatedly? If WSO. Popup ("program is running, please do not run this program repeatedly!") "& VbCrLf & VbCrLf & _" Exit the program you have run, press OK, otherwise press Cancel. (Automatically cancel after 3 seconds) "_, 3," warning ", 1) = 1 Then killmeallrun end If Set WSO = Nothing ' warninginfo ' Warning: "," The program has run, please do not run this program repeatedly!! ", 1 Wscript.Quit End If End Sub ' detects whether the function Isrun (AppPath) is repeatedly run Isrun=false for each PS in Getobje CT ("winmgmts:\\.\root\cimv2:win32_process"). Instances_ ' If Lcase (ps.name) = "Mshta.exe" Then IF Lcase (Ps.nam E) = "Wscript.exe" Then IF InStr (Lcase (Ps.commandline), Lcase (AppPath)) Then i=i+1 ' If Next if i>1 then Isrun=true End Function ' terminates its 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 (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 = no end Function ' ======= ==================================================================================== ' Check operating system version Sub CheckOS () Dim OS    _ver os_ver = getsystemversion If os_ver >= or Os_ver <=-Then "does not support the operating system!" ", 48+4096," warning "Wscript.Quit ' exit Program end If end Sub ' Get OS VersionThis 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_i Nfo.
    Version, ".")
 Getsystemversion = Cint (Os_version_arr (0) & Os_version_arr (1)) End Function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.