Skip to content

Instantly share code, notes, and snippets.

@mbrownnycnyc
Created March 27, 2013 12:19
Show Gist options
  • Save mbrownnycnyc/5253771 to your computer and use it in GitHub Desktop.
Save mbrownnycnyc/5253771 to your computer and use it in GitHub Desktop.
vbscript wrapper for devcon to disable a given list of devices (older script_
'on error resume next
Set objShell = CreateObject("WScript.Shell")
DeviceEnabledList = ""
DEVCONEXEC = ""
Main()
wscript.quit
Function Main()
Call FindArch()
Call CheckDevice("v1394")
Call CheckDevice("cdrom")
Call SendEmail("systemalertsny@domain.com")
End Function
Function FindArch()
procarch = objshell.RegRead("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\PROCESSOR_ARCHITECTURE")
if procarch = "x86" then
DEVCONEXEC = "\\..\scripts$\res\devcon-i386\devcon.exe"
end if
if procarch = "AMD64" or procarch = "IA64" then
DEVCONEXEC = "\\..\scripts$\res\devcon-ia64\devcon.exe"
end if
End Function
Function CheckDevice(devicetype)
'find current status
set objcheckdevice = objshell.exec(DEVCONEXEC & " status *" & devicetype & "*")
do while objcheckdevice.status = 0
wscript.sleep 100
loop
'check for "No matching devices found." == no device
'check for !"Device is disabled." == assume the device is enabled
DeviceCheck = objcheckdevice.stdout.readall
if instr(DeviceCheck, "No matching devices found.") > 0 then
'okay
elseif instr(DeviceCheck, "Device is disabled.") > 0 then
CheckDevice = false
elseif instr(DeviceCheck, "Device is disabled.") = 0 then
CheckDevice = true
DeviceEnabledList = DeviceEnabledList & " " & devicetype & " "
'disable device
DisableDevice(devicetype)
end if
End Function
Function DisableDevice(devicetype)
'v1394 or cdrom
set objdisabledevice = objshell.exec(DEVCONEXEC & " disable *" & devicetype & "*")
do while objdisabledevice.status = 0
wscript.sleep 100
loop
CheckDevice(devicetype)
End Function
Function SendEmail(TargetAddress)
workstationname = objShell.ExpandEnvironmentStrings("%COMPUTERNAME%")
if len(DeviceEnabledList) > 0 then
EmailBody = workstationname & " had the following devices enabled, which are now disabled: " & vbnewline & DeviceEnabledList
'send email
Set objEmailSender = objShell.Exec("cscript \\..\scripts$\sendmail.vbs /from:workstation-gremlin@domain.com /to:" & TargetAddress & " /subject:"" " & workstationname & " has a banned device enabled"" /body:""" & EmailBody & """")
end if
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment