Jump to content

Browse to directory and determine if all hotfixes exist


Recommended Posts

I am super new to Autoit, but it seems like a great tool.

I would like to browse to a directory and verify that all predetermined Windows hot fixes exist. I would also like to generate a message box which states whether all the hot fixes exist or list those that did not exist in the directory. Which way is the best way to go the fileexists function or trying to read the list into and array and comparing to something like a text file which holds all the names of those predetermined hot fixes. Any sample code would be greatly appreciated. Thank you in advance for any help provided.

Edited by JimC
Link to comment
Share on other sites

I am super new to Autoit, but it seems like a great tool.

I would like to browse to a directory and verify that all predetermined Windows hot fixes exist. I would also like to generate a message box which states whether all the hot fixes exist or list those that did not exist in the directory. Which way is the best way to go the fileexists function or trying to read the list into and array and comparing to something like a text file which holds all the names of those predetermined hot fixes. Any sample code would be greatly appreciated. Thank you in advance for any help provided.

This is a very basic script that opens a text file labeled docs.txt on the desktop, copies it to an array then creates another array with the files in c:\temp named update1, update2, update3, etc. The arrays are then displayed, you could compare the arrays against one another and write a text file with a list of updates that aren't in the list. Hope this helps.

#include <Array.au3>
Dim $arr1[1]
Dim $arr2[1]
$path = "c:\temp\update"

$file1 = FileOpen("C:\Documents and Settings\" & @UserName & "\Desktop\docs.txt", 0)
If $file1 = -1 Then MsgBox(0, "Error", "Unable to open document.")

While 1
   $line1 = FileReadLine($file1)
    If @error = -1 Then ExitLoop
    _ArrayAdd($arr1,$line1)
WEnd
FileClose($file1)

$num = 1
While 1
If FileExists($path & $num) Then _ArrayAdd($arr2,"update"   & $num)
If Not FileExists ($path & $num) Then ExitLoop
$num = $num + 1
WEnd

_ArrayDisplay($arr1)
_ArrayDisplay($arr2)
Edited by WhiteSpace
Link to comment
Share on other sites

This is a very basic script that opens a text file labeled docs.txt on the desktop, copies it to an array then creates another array with the files in c:\temp named update1, update2, update3, etc. The arrays are then displayed, you could compare the arrays against one another and write a text file with a list of updates that aren't in the list. Hope this helps.

#include <Array.au3>
Dim $arr1[1]
Dim $arr2[1]
$path = "c:\temp\update"

$file1 = FileOpen("C:\Documents and Settings\" & @UserName & "\Desktop\docs.txt", 0)
If $file1 = -1 Then MsgBox(0, "Error", "Unable to open document.")

While 1
   $line1 = FileReadLine($file1)
    If @error = -1 Then ExitLoop
    _ArrayAdd($arr1,$line1)
WEnd
FileClose($file1)

$num = 1
While 1
If FileExists($path & $num) Then _ArrayAdd($arr2,"update"   & $num)
If Not FileExists ($path & $num) Then ExitLoop
$num = $num + 1
WEnd

_ArrayDisplay($arr1)
_ArrayDisplay($arr2)
Better than checking if files exist, check which ones have been applied.

That info is in the registry but off the top of my head I don't remember where.

I know it's also usually stored in HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall if it's uninstallable but not all of them are.

Which ever key you use you will need RegEnumKey()

Edit:

Also IIRC there is either a .txt or .ini file in the Widows folder that contains a list of applied hotfixes.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Also I have this VBS code that will do it. I'm not about to convert it and thin it out right now but someone else might tackle it for you.

Set objSession = CreateObject("Microsoft.Update.Session")

Set objSearcher = objSession.CreateUpdateSearcher

intHistoryCount = objSearcher.GetTotalHistoryCount

Set colHistory = objSearcher.QueryHistory(1, intHistoryCount)

For Each objEntry in colHistory

Wscript.Echo "Operation: " & objEntry.Operation

Wscript.Echo "Result code: " & objEntry.ResultCode

Wscript.Echo "Exception: " & objEntry.Exception

Wscript.Echo "Date: " & objEntry.Date

Wscript.Echo "Title: " & objEntry.Title

Wscript.Echo "Description: " & objEntry.Description

Wscript.Echo "Unmapped exception: " & objEntry.UnmappedException

Wscript.Echo "Client application ID: " & objEntry.ClientApplicationID

Wscript.Echo "Server selection: " & objEntry.ServerSelection

Wscript.Echo "Service ID: " & objEntry.ServiceID

i = 1

For Each strStep in objEntry.UninstallationSteps

Wscript.Echo i & " -- " & strStep

i = i + 1

Next

Wscript.Echo "Uninstallation notes: " & objEntry.UninstallationNotes

Wscript.Echo "Support URL: " & objEntry.SupportURL

Wscript.Echo

Next

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

The reason I would like to check is to make sure that all the hot fixes that should be applied prior to actually applying them so that the process doesn't have to be done again after the fact. That is why I was looking for a way to compare the actual hot fixes that exist in the directory compared to the official list which would be held in a text file. Thanks for your input.. Does this idea make sense? Again thanks in advance for any help ...

Link to comment
Share on other sites

The reason I would like to check is to make sure that all the hot fixes that should be applied prior to actually applying them so that the process doesn't have to be done again after the fact. That is why I was looking for a way to compare the actual hot fixes that exist in the directory compared to the official list which would be held in a text file. Thanks for your input.. Does this idea make sense? Again thanks in advance for any help ...

It still makes more sense to check the hotfixes that are currently applied not just checking for existing files and folders. If a hotfix has been uninstalled then the uninstall folder and files could still exist. The only other way of checking properly would be to check the version and date of each file installed by each hot fix. That would be a horror show in itself. If a hotfix is uninstalled then the entries fopr it are removed from the registry. Or how about the situation where a hotfix has been downloaded but not actually installed?

EDIT: Using the registry method gives a better indivation of whats been installed than any other will. So you wouldn't install something that has already been done. And generally a hotfix will not overwrite a newer file anyway. The exception to that is when MS has a bad hotfix and the want to do a partial rollback with a new hotfix so they do that part of the checking for you.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

When using an arry to store the values of the hot fixes to run is there a way to then sort the array to make sure it is in proper order. Or would I have to adjust the svcpack.inf file to make sure the hot fixes get applied in the proper order.

Thanks,

Link to comment
Share on other sites

When using an arry to store the values of the hot fixes to run is there a way to then sort the array to make sure it is in proper order. Or would I have to adjust the svcpack.inf file to make sure the hot fixes get applied in the proper order.

Thanks,

#include <array.au3>

_ArraySort($Array, 0, 1)

Edit: If you are still going the file route then take a serious look at _FileListToArrayEx(). There is a link someplace in Example Scripts. Then you can sort that by date.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

#include <array.au3>

_ArraySort($Array, 0, 1)

Edit: If you are still going the file route then take a serious look at _FileListToArrayEx(). There is a link someplace in Example Scripts. Then you can sort that by date.

Ahh, I haven't used that command before, that is much better than what I originally proposed. JimC, here is a revised script following GEOSoft's advice, I also sorted the arrays before displaying them.

#include <File.au3>
#include <Array.au3>
Dim $arr1[1]
Dim $arr2[1]
$path = "c:\temp"

$file1 = FileOpen("C:\Documents and Settings\" & @UserName & "\Desktop\docs.txt", 0)
If $file1 = -1 Then MsgBox(0, "Error", "Unable to open document.")

While 1
   $line1 = FileReadLine($file1)
    If @error = -1 Then ExitLoop
    _ArrayAdd($arr1,$line1)
WEnd
FileClose($file1)

$arr2 = _FileListToArray($path)
If @error Then Exit
_ArraySort($arr1, 0, 1)
_ArraySort($arr2, 0, 1)


_ArrayDisplay($arr1)
_ArrayDisplay($arr2)
Link to comment
Share on other sites

Function by amel27:

#Include <Array.au3>

$aList = _GetHotFixes ()
For $i=1 To $aList[0][0]
    ConsoleWrite ($aList[$i][0] & @CRLF)
    ConsoleWrite ($aList[$i][1] & @CRLF)
    ConsoleWrite ($aList[$i][2] & @CRLF & @CRLF)
Next

Func _GetHotFixes ()
    Local $i, $j, $k, $iKey, $jKey, $kKey
    Local Const $root1 = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\HotFix"
    Local Const $root2 = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Updates"
    Local $arrList[1] = [0], $arrHFix[1][3] = [[0,0,0]]
    $i=1
    While True
        $iKey = RegEnumKey ($root1, $i)
        If @error Then  ExitLoop
        $arrList[0]+=1
        ReDim $arrList[$arrList[0]+1]
        $arrList[$arrList[0]] = $iKey
        $i+=1
    Wend
    $i=1
    While True
        $iKey = RegEnumKey ($root2, $i)
        If @error Then  ExitLoop
        $j=1
        While True
            $jKey = RegEnumKey ($root2 & '\' & $iKey, $j)
            If @error Then  ExitLoop
            If _ArraySearch ($arrList, $jKey, 1) > 0 Then
                $arrHFix[0][0] +=1
                ReDim $arrHFix[$arrHFix[0][0]+1][3]
                $arrHFix[$arrHFix[0][0]][0]=$jKey
                $arrHFix[$arrHFix[0][0]][1]=$iKey
                $arrHFix[$arrHFix[0][0]][2]=RegRead ($root2 & '\' & $iKey & '\' & $jKey, 'Description')
                If @error Then $arrHFix[$arrHFix[0][0]][2]=RegRead ($root2 & '\' & $iKey & '\' & $jKey, 'PackageName')
            ElseIf StringRegExp ($jKey, '^SP[1-9]$') Then
                $k=1
                While True
                    $kKey = RegEnumKey ($root2 & '\' & $iKey & '\' & $jKey, $k)
                    If @error Then  ExitLoop
                    If _ArraySearch ($arrList, $kKey, 1) > 0 Then
                        $arrHFix[0][0] +=1
                        ReDim $arrHFix[$arrHFix[0][0]+1][3]
                        $arrHFix[$arrHFix[0][0]][0]=$jKey
                        $arrHFix[$arrHFix[0][0]][1]=$iKey
                        $arrHFix[$arrHFix[0][0]][2]=RegRead ($root2 & '\' & $iKey & '\' & $jKey & '\' & $kKey, 'Description')
                        If @error Then $arrHFix[$arrHFix[0][0]][2]=RegRead ($root2 & '\' & $iKey & '\' & $jKey, 'PackageName')
                    EndIf
                    $k+=1
                Wend
            EndIf
            $j+=1
        Wend
        $i+=1
    Wend
    Return $arrHFix
EndFunc

Work for me great!

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

I would like to read the hotfixes into an array. While integrating the hotfixes to the source (not an actual PC) how can I show a progress bar or countdown as to how many more patches to integrate ?

Thanks again for any help !!!!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...