Jump to content

Automating Windows Update


 Share

Recommended Posts

Dear all,

First I would like to thank you for answering hundreds of my questions through the search function. It helped me a lot in the past months to create helpful AutoIt scripts.

Now I came to the point where I would like to automate the Windows Update function on some workstations that will get a big software bundle installed. This is necessary to guarantee a smooth installation process, because some to-be-installed software hangs during installation, if there are pending Windows Updates or there is a pending reboot (eg SQL Server 2008 R2 and SQL Server 2012).

The whole script itself runs perfectly fine, but once a month my firm pushes new Windows Updates, and at that time installation frequently bugs out.

All I did before was checking the registry for Windows updates right at the start of the script so the user can interact immediatly before leaving the computer overnight for the installation process, but unfortunately GPO forces the computer to check every hour for new Windows Updates, so it may happen, that during installation new updates are found and installed while SQL Server is being installed, and this leads to critical errors aborting the script.

What I would very much like to do:

1. Check for updates

2. Install updates (if found)

3. Reboot machine (if necessary)

4. Start installation of to-be-installed software

Here is my current check for Windows updates, which is of course not sufficent:

; check for pending Windows updates
If RegRead("HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\UAS", "UpdateCount") <> "0x0" Then
   MsgBox(16, "Installation failed", "Please run Windows Update before software installation")
   Exit
EndIf

Please considerate this is my first post in the forum. There might be some information missing :-)

Thanks for reading and thank you very much in advance for any help!

Link to comment
Share on other sites

Welcome to AutoIt!

I did a little research and came across these websites that may be helpful:

http://stackoverflow.com/questions/5102900/registry-key-location-for-security-update-and-hotfixes

http://msdn.microsoft.com/en-us/library/aa387099%28VS.85%29.aspx

As for getting a list of updates in the registry, I had Windows download an update (but not install) and the "CurrentState" value for it was 96. Previously installed updates had a value of 112. At least on my Win7 x64 machine. I wrote a little code to find packages that did not have a value of 112. There are other CurrentState values, but I don't know their meaning. You can modify the code to include install location in the array. Check your registry at the locations listed in the code below for all of it's info. On my Win7 machine, I had to compile it as x64 and run as an admin for it to work. You may have to write two versions: one compiled as x86 and have it check to see if the OS is x86 or x64. If it is x86, it can go ahead and read the registry. If the OS is x64, have the x86 executable call the x64 version.

Hopefully, this will give you some ideas.

#include <array.au3>
#RequireAdmin
Dim $swList[1][2]

$j = 0
For $i = 1 To 1000
    Local $var = RegEnumKey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\Packages", $i)
    Local $var2 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\Packages\" & $var, "CurrentState")
    If $var2 <> 112 Then ; or you could use $var2 = 96
        $swList[$j][0] = $var
        $swList[$j][1] = $var2
        ReDim $swList[$j + 2][2]
        $j += 1
    EndIf
Next

_ArrayDisplay($swList)

 

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...