Page 1 of 1 1
Topic Options
#149569 - 2005-10-09 07:53 PM Hot Fixes
JST Offline
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
#149570 - 2005-10-09 07:54 PM Re: Hot Fixes
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
There are several sort UDFs to choose form.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#149571 - 2005-10-09 08:04 PM Re: Hot Fixes
JST Offline
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
#149572 - 2005-10-09 08:12 PM Re: Hot Fixes
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Then you didn't search for e.g. SORT. For multi-dimensional array sorting, the best approach is using a database and SQL to perform the sorting.
_________________________
There are two types of vessels, submarines and targets.

Top
#149573 - 2005-10-10 10:52 AM Re: Hot Fixes
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
If only want the last one why do you need to sort?

Just keep a track of one hotfix and it's date. If the next hotfix that you enumerate is later then set your remembered hotfix and date to its value.

You will need to decide how to handle hotfixes with the same date and time.

If the date is not in "YYYY-MM-DD HH:MM:SS" order then re-order it - it will make you comparison much easier.

Top
#149574 - 2005-10-10 02:35 PM Re: Hot Fixes
Richard H. Administrator Offline
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. Offline
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 Offline
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

_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#149577 - 2005-10-10 06:06 PM Re: Hot Fixes
Radimus Moderator Offline
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
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#149578 - 2005-10-11 10:00 AM Re: Hot Fixes
Richard H. Administrator Offline
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
Page 1 of 1 1


Moderator:  Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.041 seconds in which 0.021 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org