Link to home
Create AccountLog in
Avatar of csilvio
csilvio

asked on

Script to disable or enable usb

We have the USB Storage locked down, and there's also a support group to whom we're giving access to open or disbale again the usb storage.

The script to enable usb storage is:

Set WSHShell = WScript.CreateObject("WScript.Shell")
WshShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\USBSTOR\Start", 4,"REG_DWORD"

and to enable:
Set WSHShell = WScript.CreateObject("WScript.Shell")
WshShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\USBSTOR\Start", 3,"REG_DWORD"

I need to merge these two options oin one script, where the user will be asked if he wants either to enable or disable the usb.

Thanks
Avatar of Shift-3
Shift-3
Flag of United States of America image

Paste the script below into a text file with a .vbs extension.  Running it will prompt the user for input and then change the registry value accordingly.



Const HKEY_LOCAL_MACHINE = &H80000002
 
strAnswer = InputBox("D - Disable USB Storage" & vbCrLf & "E - Enable USB Storage", "USB Storage")
 
If LCase(Left(strAnswer, 1)) = "d" Then
	strValue = 4
ElseIf LCase(Left(strAnswer, 1)) = "e" Then
	strValue = 3
Else
	MsgBox "Operation canceled."
	WScript.Quit
End If
 
Set objRegistry = GetObject("winmgmts:\\.\root\default:StdRegProv")
 
strKeyPath = "SYSTEM\CurrentControlSet\Services\USBSTOR"
strValueName = "Start"
 
objRegistry.SetDWORDValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strValue
 
If LCase(Left(strAnswer, 1)) = "d" Then
	MsgBox "USB storage disabled."
Else
	MsgBox "USB storage enabled."
End If

Open in new window

Avatar of csilvio
csilvio

ASKER

Hey thanks that qworks.

But can you make it a bit straight forward?

Maybe by just having two buttons to press, one disable and other enable, instead of inputting anything. By just clicking either enable or disable.

Thanks :)
ASKER CERTIFIED SOLUTION
Avatar of Shift-3
Shift-3
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of csilvio

ASKER

That's great thanks a lot.

Thanks for your immediate reply and for being so helpful.
But how we use it?