Tuesday, June 30, 2015

Disabling USB Selective Suspend via a GPO on Windows 7

I thought I'd written about this earlier, but I searched today and couldn't find it.

My customer has a fidgety business-specific printer that doesn't seem to care for USB selective suspend.  They wanted to turn it off for all of their print machines with a GPO.

Windows includes the PowerCfg.exe tool for configuring power management. 

To Change a single setting in a Windows 7 power plan for AC mode run:
PowerCfg.exe -setacvalueindex (Guid of Power Plan) (Guid of Category) (Guid of Setting) (Value)

To Change a single setting in a Windows 7 power plan for DC/Battery mode run:
PowerCfg.exe -setdcvalueindex (Guid of Power Plan) (Guid of Category) (Guid of Setting) (Value)


My power plan is set to the out-of-box High Performance profile.
I run PowerCfg.exe /L to list the guids of my power plans.
I run PowerCfg.exe /Q to list the categories, settings, and values available in the power plans.

This yields:
8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c (High Performance)
2a737441-1930-4402-8d77-b2bebba308a3  (USB settings)
48e6b7a6-50f5-4782-a5d4-53bb8f07e226  (USB selective suspend setting)


So, for me, to Disable selective suspend on Windows 7 in the High Performance Power plan when plugged in, I run:
Powercfg.exe -setacvalueindex 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c 2a737441-1930-4402-8d77-b2bebba308a3 48e6b7a6-50f5-4782-a5d4-53bb8f07e226 0

I ran ProcMon while running this and found it creates a single registry entry:
 
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes\8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c\2a737441-1930-4402-8d77-b2bebba308a3\48e6b7a6-50f5-4782-a5d4-53bb8f07e226]
"ACSettingIndex"=dword:00000000

... and that's what goes in the GPO.  Magic.

Note: The procedure is different for Windows 7 and XP.  The above is Win7+.  If you need to change it on XP then use the following registry key per MS kb895962

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\USB
Entry: DisableSelectiveSuspend
Type: DWORD
Value: 1 disables selective suspend mode. 0 enables selective suspend mode.

Friday, June 12, 2015

IPv6 in the Wild

Today I noticed something interesting.






I pinged Google.com to verify connectivity and name resolution and... holy sheep!  It resolved to an Ipv6 AAA address and responded via IPv6.  I've never seen it up/running/alive and on a real network before.  That's awesome!


Thursday, June 4, 2015

Quickie: Finding Web redirects with Curl

Today I was given a list of Domain names and asked to determine if they were real sites or simply redirects to another site.

The redirects have 301 and 302 http status codes, so I was able to use curl for this.

I saved the URLs into a text file, sitelist.txt.
Then ran this script.

while read i; do
 echo $i >>results.txt
 curl -s -w "%{http_code} %{url_effective}\\n" "$p" -o /dev/null >> results.txt
done <sitelist.txt

Filtering the output to show only the lines that started with a 30x status code is easy with grep.
cat results.txt  | grep '^30'

To grep, the caret ^ matches the start of the line.  That makes this command equivalent to "dump out the results.txt file and filter to only show me lines that start with 30.

Magic!

(This script is Linux specific, but if you've got the windows versions of grep and curl then the following, completely untested code, batch file should work.)

for /F %%i in (sitelist.txt) do {
  echo %%i>>results.txt
  curl -s -w "%{http_code} %{url_effective}\\n" "$p" -o /dev/null >>results.txt
}