#149569 - 2005-10-09 07:53 PM
Hot Fixes
|
JST
Fresh Scripter
Registered: 2004-08-26
Posts: 8
|
I need help with sorting by dates. I am generating a list of all hot fixes installed, but I need to report only on which one was the last one to install and when did it installed (date and time).
How can I sort by date and report only the latest?
Thanks
|
|
Top
|
|
|
|
#149571 - 2005-10-09 08:04 PM
Re: Hot Fixes
|
JST
Fresh Scripter
Registered: 2004-08-26
Posts: 8
|
Les, can you point me to at least one UDF specific to sorting. I need to sort an array by date when I enumerate the registry.
I was searching UDF's whole day.
|
|
Top
|
|
|
|
#149574 - 2005-10-10 02:35 PM
Re: Hot Fixes
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Just discovered that the "InstalledDate" value for updates is sometimes in US format and sometimes in European format!
Here is an example of how to find the latest update. Unfortunately it will fail because of the brain-dead implementation of InstalledDate, but if you are reading the details from somewhere with a consistant format you should be able to adapt it to your needs: Code:
Break ON $=SetOption("Explicit","ON") $=SetOption("WrapAtEOL","ON") Dim $sKeyUpdate $sKeyUpdate="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Updates" "Most recent update="+udfGetLatestKey($sKeyUpdate) ? Exit 0 Function udfGetLatestKey($sKeyRoot) Dim $iIndex,$sKey,$sHighKey,$sHighKeyDate $sHighKeyDate="" $iIndex=0 $sKey=EnumKey($sKeyRoot,$iIndex) While Not @ERROR $sKey=$sKeyRoot+"\"+$sKey If ReadValue($sKey,"Type")="Update" If udfFixDate(ReadValue($sKey,"InstalledDate")) > $sHighKeyDate $udfGetLatestKey=$sKey $sHighKeyDate=udfFixDate(ReadValue($sKey,"InstalledDate")) EndIf EndIf $sKey=udfGetLatestKey($sKey) If udfFixDate(ReadValue($sKey,"InstalledDate")) > $sHighKeyDate $udfGetLatestKey=$sKey $sHighKeyDate=udfFixDate(ReadValue($sKey,"InstalledDate")) EndIf $iIndex=$iIndex+1 $sKey=EnumKey($sKeyRoot,$iIndex) Loop EndFunction Function udfFixDate($sDate) $sDate=Split($sDate+"//","/") $udfFixDate=Right("0000"+$sDate[2],4)+"-"+Right("00"+$sDate[0],2)+"-"+Right("00"+$sDate[1],2) EndFunction
|
|
Top
|
|
|
|
#149575 - 2005-10-10 05:56 PM
Re: Hot Fixes
|
Chris S.
MM club member
   
Registered: 2002-03-18
Posts: 2368
Loc: Earth
|
If you are using Windows XP you can take advantage of fnDateTime() to return a KiXtart (or localized, WMI, or FILETIME) friendly date regardless of the time format.
|
|
Top
|
|
|
|
#149576 - 2005-10-10 06:02 PM
Re: Hot Fixes
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
This makes it automatic. Just dump the patches in the setup folder and ignore it... As long as the user is local admin of course.
Code:
;************************************ XP HotFix Updates ***************************************** $MaxSize= 500000 $arrkey = arrEnumKey('HKLM\SOFTWARE\Microsoft\Updates\Windows XP\SP3') $arrdir = FileList($setup+'\Hotfixes\WinXP','.exe',1) if not @error $reboot = 0 for each $dir in $arrdir $installed = 0 $parsed = split($dir,'-')[1] for each $key in $arrkey if $key = $parsed $installed = 1 endif next if not $installed if (@ras and GETFILESIZE($dir) < $MaxSize) or not @ras $=sendmessage(@wksta,"A CRTICAL upgrade is now starting. Your computer will restart on it's own in about 2-3 minutes.") ? color c+/n ' Installing Security Update '+$parsed shell '%comspec% /c ' + $dir + ' /passive /norestart' $reboot = 1 endif endif next if $reboot ShutDown ('', 'Updates have been applied that require your computer to restart', 5, 1, 1) quit endif endif
|
|
Top
|
|
|
|
#149577 - 2005-10-10 06:06 PM
Re: Hot Fixes
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
if retrospect, I may edit this to use ascan() instead of one of the for/each loops
|
|
Top
|
|
|
|
#149578 - 2005-10-11 10:00 AM
Re: Hot Fixes
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Quote:
If you are using Windows XP you can take advantage of fnDateTime() to return a KiXtart (or localized, WMI, or FILETIME) friendly date regardless of the time format.
No I can't, as the dates are stored in human readable string format 
For example on my machine .NET patch M886903 has an InstalledDate of 18/02/2005 whereas Q823718 has an InstalledDate of 08/21/2003.
Sometimes the month/days are not even zero-filled 
While it is trivial to determine the format of the dates in the example above, no UDF is going to help determine whether 01/02/2005 is the 1st of February or the 2nd of January.
|
|
Top
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 2220 anonymous users online.
|
|
|