Monday, November 26, 2007

Forcing a PC to reboot through task scheduler

So you want to schedule a PC to reboot through the task scheduler. It works sometimes, but not every time. Microsoft has created multiple shutdown commands. Below is a batch file which seems to work 100% of the time in my environment. We use the built in XP shutdown command first, then the old NT4 resource kit shutdown command, then again try the XP.

It seems that sometimes during shutdown, a program will hang the process. These additional shutdown commands seem to get it past that.

rem Reboots this PC

shutdown -r -t 90 -f -c "Nightly reboot occuring in 90 seconds to apply patches"
shutdown2 /L /R /T:160 /Y /C "Nightly reboot occuring in 90 seconds to apply patches"
shutdown -r -t 60 -f -c "Nightly reboot occuring in 90 seconds to apply patches"
sleep 100


Sometimes I stick sleep commands between the shutdowns. I don't fully understand this issue, but the above batch file works for me.

Monday, November 12, 2007

Fixing WSUS for all the various reasons.

So you cloned a PC and it has the same WSUS GUID. Sysprep didn't help.
Or you put a volume license onto an OEM, and now WSUS fails.

Whatever the reason, here is the batch file to fix it.


net stop wuauserv
rem Transflo depends on BITS and must be stopped first
net stop "TRANSFLO Client Agent Service"
@rem one known dependent service. Add others you know of.
net stop "Background Intelligent Transfer Service"

@rem Make sure the proper GPOs are applied
gpupdate

@rem re register services that may be broken

REGSVR32 /s WUAUENG.DLL
REGSVR32 /s WUAUENG1.DLL
REGSVR32 /s ATL.DLL
REGSVR32 /s WUCLTUI.DLL
REGSVR32 /s WUPS.DLL
REGSVR32 /s WUPS2.DLL
REGSVR32 /s WUWEB.DLL

REGSVR32 /s ATL.DLL

rem Remove the temp directories.

rd %windir%\SoftwareDistribution\DataStore\logs /s /q
rd %windir%\SoftwareDistribution\DataStore /s /q
rd %windir%\SoftwareDistribution\Download /s /q
rd %windir%\SoftwareDistribution\EventCache /s /q


rem Some machines will fail to re-install MSI 3.1 after
rem all of this. About 1%. The fix is below.
rem It is up to you to determine if you want to download
rem and install these fixes. Remmed out.

rem call WindowsXP-KB927891-v3-x86-ENU.exe" /quiet /norestart
rem call Windows2000-KB927891-x86-ENU.EXE" /quiet /norestart

regedit /s resetGUID.reg

net start wuauserv

wuauclt /resetauthorization /detectnow



---------------------------------------------------------------
Here is the resetGUID.reg file
---------------------------------------------------------------
REGEDIT4

// Registry file generated by the Application Launcher.

[HKEY_LOCAL_MACHINE\SOFTWARE]

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft]

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows]

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion]

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate]
"AccountDomainSid"=-
"PingID"=-
"SusClientId"=-







I've ran this on hundreds of machines with no problem. This is provided as-is. I provide no warranty.

Friday, November 2, 2007

Example code in VB to set color of subitems

Here is code that rips through a file to set the color of a listview item color and subitem color.

This is VB6. I found a lot of people asking how to do this, but no real solutions. It's not that hard after you know what the syntax is;


Do Until EOF(fnum1)
Line Input #fnum1, Linein
aRRy = Split(Linein, ",")
If UBound(aRRy) = 10 Then
SSN = Trim$(Replace(aRRy(8), Chr$(34), vbNullString))
Doctype = UCase(Replace(aRRy(9), Chr$(34), vbNullString))
TIFfile = UCase(Replace(aRRy(7), Chr$(34), vbNullString))
BatchID = Trim$(Replace(aRRy(10), Chr$(34), vbNullString))

ListView.ListItems.Add , , SSN
ListView.ListItems.Item(ListView.ListItems.Count).SubItems(1) = Doctype
Debug.Print TIFfile

ListView.ListItems.Item(ListView.ListItems.Count).SubItems(2) = TIFfile
If Len(SSN) <> 9 Then
ListView.ListItems.Item(ListView.ListItems.Count).ForeColor = vbRed
Else
ListView.ListItems.Item(ListView.ListItems.Count).ForeColor = vbBlack
End If
If EXIST(TIFfile) Then
ListView.ListItems.Item(ListView.ListItems.Count).ListSubItems.Item(2).ForeColor = vbBlack
Else
ListView.ListItems.Item(ListView.ListItems.Count).ListSubItems.Item(2).ForeColor = vbRed
End If

End If
Loop
Close #fnum1