views:

558

answers:

7

I'm specifically interested in Windows 2000/XP, but Vista would be interesting too (if different).

I was thinking along the lines of task scheduling a batch file or equivalent on a daily basis.

EDIT: Sorry, I should have provided more info. The question pertains to 10 machines which I manually apply updates. I don't want to install the updates programatically, but just find out if there are updates ready to download/install (i.e. the update shield icon in the system tray is indicating this) using a batch or script. Thanks.

+1  A: 

Windows SUS works very well for several machines on a network.

Austin Salonen
A: 

The "easiest" way to tell is to setup Windows Updates to occur nightly and download the updates if available which then puts the update shield icon in the system tray. Just glance at the tray to see if the icon is present.

You could also setup Windows to check nightly for the updates, then download and install them at a specified time.

mdzindzeleta
A: 

In regards to what mdsindzeleta said - going about this programatically probably isn't the best solution. I would use the features built into Windows XP to download and install updates. I'm assuming that Vista has similar features.

Thomas Owens
+1  A: 

There appears to be some information in WindowsUpdate.log in the Windows directory. It's a bit cryptic, but it might help you.

I found this information that might help you:

http://msdn.microsoft.com/en-us/library/aa387102(VS.85).aspx

Adam Ruth
A: 

I believe Windows updates are downloaded using the BITS service. You could use Bitsadmin.exe found in the Windows Support Tools. From the command line you can run bitsadmin.exe /list and you can see the status of BITS jobs. (i.e. download progress, job name, job status)

Cj Anderson
A: 

You could use WUApiLib

            UpdateSessionClass session = new UpdateSessionClass();

            IUpdateSearcher search = session.CreateUpdateSearcher();

            ISearchResult result = search.Search("IsInstalled=0 and IsPresent=0 and Type='Software'");

            int numberOfUpdates = result.Updates.Count - 1;

            Log.Debug("Found " + numberOfUpdates.ToString() + " updates");

            UpdateCollection updateCollection = new UpdateCollection();

            for (int i = 0; i < numberOfUpdates; i++)
            {
                IUpdate update = result.Updates[i];

                if (update.EulaAccepted == false)
                {
                    update.AcceptEula();
                }

                updateCollection.Add(update);
            }

            if (numberOfUpdates > 0)
            {
                UpdateCollection downloadCollection = new UpdateCollection();

                for (int i = 0; i < updateCollection.Count; i++)
          {
              downloadCollection.Add(updateCollection[i]);
          }

                UpdateDownloader downloader = session.CreateUpdateDownloader();

                downloader.Updates =  downloadCollection;

                IDownloadResult dlResult = downloader.Download();

                if (dlResult.ResultCode == OperationResultCode.orcSucceeded)
                {
                    for (int i = 0; i < downloadCollection.Count; i++)
                    {
                        Log.Debug(string.Format("Downloaded {0} with a result of {1}", downloadCollection[i].Title, dlResult.GetUpdateResult(i).ResultCode));
                    }

                    UpdateCollection installCollection = new UpdateCollection();

                    for (int i = 0; i < updateCollection.Count; i++)
                    {
                        if (downloadCollection[i].IsDownloaded)
                        {
                            installCollection.Add(downloadCollection[i]);
                        }
                    }

                    UpdateInstaller installer = session.CreateUpdateInstaller() as UpdateInstaller;

                    installer.Updates = installCollection;

                    IInstallationResult iresult = installer.Install();

                    if (iresult.ResultCode == OperationResultCode.orcSucceeded)
                    {
                        updated = installCollection.Count.ToString() + " updates installed";

                        for (int i = 0; i < installCollection.Count; i++)
                        {
                            Log.Debug(string.Format("Installed {0} with a result of {1}", installCollection[i].Title, iresult.GetUpdateResult(i).ResultCode));
                        }

                        if (iresult.RebootRequired == true)
                        {
                            ManagementClass mcWin32 = new ManagementClass("Win32_OperatingSystem");

                            foreach (ManagementObject shutdown in mcWin32.GetInstances())
                            {
                                shutdown.Scope.Options.EnablePrivileges = true;
                                shutdown.InvokeMethod("Reboot", null);
                            }
                        }
                    }`
Alex
A: 

In the end, Windows SUS wasn't an option, so I'm using the following in a batch file conjunction with ActiveState ActivePerl (recommended):

perl -nle "print $_ if m/updates detected/i" < c:\Windows\WindowsUpdate.log

This might be crude or dirty, and might break in future, but it currently does what I need.

Thanks for all the ideas.

Umber Ferrule