Windows XP stop startup scripts hang

From richud.com
Jump to navigation Jump to search

If Windows XP is on a domain and asyncronous policy refresh is disabled (ala Win2000) Winxp will hang until timeout if it cannot find the domain controller and a network is present. This will happen if you have a wireless that is associated to a live network that isn't part of the domain e.g. a hotspot somewhere.

To get around this, you can disable the wireless card on shutdown and reenable on startup AFTER the policy refresh would have taken place (where it sees no network and carries on without hanging)

You can do this by running gpedit and setting up startup and shutdown scripts

  • If not already present create the folder structure c:\WINDOWS\system32\GroupPolicy\Machine\Scripts\Startup\
  • Copy devcon.exe and the code below as a file (saved as wifi.bat) into the Startup\ folder.
  • Run gpedit.msc , navigate to Computer Configuration > Windows Settings > Scripts (startup/shutdown)
  • 'Add' a startup script, point it to c:\WINDOWS\system32\GroupPolicy\Machine\Scripts\Startup\wifi.bat, with 'script parameters' set to 'enable'
  • 'Add' a shutdown script, point it to c:\WINDOWS\system32\GroupPolicy\Machine\Scripts\Startup\wifi.bat, with 'script parameters' set to 'disable' (the name will show the full path rather than just wifi.bat as on startup)
  • When you next reboot the card will be disabled, and reenabled on startup, the log will be put in c:\WINDOWS\wifi.log

Script (wifi.bat)

@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
SETLOCAL ENABLEEXTENSIONS

set log=c:\windows\wifi.log

date /t  >> %log% && time /t >> %log% && echo "runmode:%1" >> %log%


for /F "delims=" %%i in ('reg query "HKLM\SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}" ^| findstr "}\\{"') do (
	reg query "%%i" /s | findstr /c:"Wireless Network" >> %log%
		if [!errorlevel!] == [0] (
			for /f "tokens=2,3 delims=\&" %%j in ('reg query "%%i" /s ^| findstr "PnpInstanceID"') do (
				%~dp0devcon.exe %1 "*%%j&%%k*" >> %log% 2>&1
			)
		)
)

Whats going on?

The network registry GUID key ({4D36E972-E325-11CE-BFC1-08002BE10318}) is gone through (it contains a sub entry for each network device) looking for anything that is a 'Wireless Network Connection', if it is, the ven/dev of the wireless device is pulled out and passed to devcon to be either enabled or disabled.

Log (c:\windows\wifi.log)

The log should look something like

28/02/2012 
09:12
"runmode:disable" 
    Name	REG_SZ	Wireless Network Connection
PCI\VEN_10EC&DEV_8172&SUBSYS_817210EC&REV_10\4&1E7655AE&0&00E2: Disabled
1 device(s) disabled.
28/02/2012 
09:28
"runmode:enable" 
    Name	REG_SZ	Wireless Network Connection
PCI\VEN_10EC&DEV_8172&SUBSYS_817210EC&REV_10\4&1E7655AE&0&00E2: Enabled
1 device(s) enabled.