' AUTHOR: Will Steele
' CREATED: 1/22/2009
' PURPOSE: The script turns off power management for USB Root Hubs.
' NOTE: Change (line 8) HcDisableSelectiveSuspend to &H00000000 to enable power management for all USB Root Hubs.
' Change (line 8) HcDisableSelectiveSuspend to &H00000001 to disable power management for all USB Root Hubs.
' Be aware this script will not display automatically in the device management tab for each USB root hub. Changes will appear
' in the GUI only after a reboot. Note also that changes are effective immediately.
' Designate hex values for registry constants to be used in script
Const HKEY_LOCAL_MACHINE = &H80000002
Const HcDisableSelectiveSuspend = &H00000001
' Specify the value for querying in the registry keys
strValueName = "HcDisableSelectiveSuspend"
strComputer = "."
' Add a key for searching in the regular expression
DriverDesc = "DriverDesc"
' Get registry root for querying
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
' Specify path to query
strKeyPath = "SYSTEM\CurrentControlSet\Control\Class\{36FC9E60-C465-11CF-8056-444553540000}"
' Get subkeys into array
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
' Initialize regular expression
set re = new regexp
' Specify pattern for regular expression
re.pattern = "Host Controller"
' Initialize a variable to use as a counter
pathCount = 0
' Loop based on the length of the arrSubKeys array returned regular expression
For pathCount = 0 To UBound(arrSubKeys)
' Create path specific strings based on array length of 10 or less
If pathCount < 10 Then
' Append path count to path string
strKeyPath = "SYSTEM\CurrentControlSet\Control\Class\{36FC9E60-C465-11CF-8056-444553540000}\000" & pathCount
' Get value of string
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,DriverDesc,strValue
' evaluate regular epxression
set test = re.Execute(strValue)
' If HcDisableSelectiveSuspect key does not exist, add it and set the value
If test.Count Then
oReg.CreateKey HKEY_LOCAL_MACHINE,strKeyPath,DriverDesc,strValueName
oReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,HcDisableSelectiveSuspend
'WScript.Echo (CStr(strKeyPath & "\" & CStr(strValueName) & " set to - " & CInt(HcDisableSelectiveSuspend)))
End If
' Create path specific string based on array length of 10 or more
Else
' Append path to path string
strKeyPath = "SYSTEM\CurrentControlSet\Control\Class\{36FC9E60-C465-11CF-8056-444553540000}\00" & pathCount
' Get value of string
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,DriverDesc,strValue
'evaluate regular expression
set test = re.Execute(strValue)
' If hcDisableSelectiveSuspend key does not exist, add it and set the value
If test.Count Then
oReg.CreateKey HKEY_LOCAL_MACHINE,strKeyPath,DriverDesc,strValueName
oReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,HcDisableSelectiveSuspend
'WScript.Echo (CStr(strKeyPath & "\" & CStr(strValueName) & " set to - " & CInt(HcDisableSelectiveSuspend)))
End If
End If
Next
' Report status of update
If CStr(HcDisableSelectiveSuspend) = 0 Then
WScript.Echo ("All USB Root Hubs have been configured to have power management enabled.")
Else
WScript.Echo ("All USB Root Hubs have been configured to have power management disabled.")
End If
<message edited by will.steele on Monday, May 04, 2009 7:24 AM>