Wednesday, July 21, 2010

Locking down USB Drives to Read Only VB Script

HKEY_LOCAL_MACHINE = &H80000002

Err.Clear
' On Error Resume Next

strComputer = inputbox ("Please Enter Computer Name","Enter Computer Name","IT-0")

' Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
' If Err.Number Then
' Wscript.Quit
' End If

On Error Resume Next
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
If Err.Number Then
WScript.Echo "Computer Name Does Not Exist"
Wscript.Quit
End If

if strcomputer = "" then

Wscript.Quit

End if

Set objReg = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")

strKeyPath = "SYSTEM\CurrentControlSet\Control\StorageDevicePolicies"

objReg.CreateKey HKEY_LOCAL_MACHINE, strKeyPath

ValueName = "WriteProtect"

DwordValue = "1"

objReg.SetDwordValue HKEY_LOCAL_MACHINE, strKeyPath, ValueName, DwordValue

If IsNull(DwordValue) Then

Wscript.Echo "The Registry Key for " & strComputer & " is not found. - ", DwordValue

Elseif DwordValue=0 then

Wscript.Echo "The USB Key for computer " & strComputer & " is now OPEN: Not Read Only! - ", DwordValue

else

Wscript.Echo "The USB Key for computer " & strComputer & " is Secured and Read Only - ", DwordValue

End If

If Msgbox("Do you want to reboot machine now for the change to take affect? " & strComputer, vbYesNo, "Reboot Machine") = vbYes then

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate,(Shutdown)}!\\" & _
strComputer & "\root\cimv2")

Set colOS = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")

For Each objOS in colOS
objOS.Reboot()
Next

End If






No comments:

Post a Comment