Best way to determine if Windows is ready to download / install Windows?

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

I thought about task lines, planning a batch file or equivalent on a daily basis.

EDIT: Sorry, I had to provide more information. The question relates to 10 machines that I manually apply for updates. I don't want to install updates programmatically, but just find out if there are updates ready for download / installation (for example, the update screen icon in the system tray indicates this) using a package or script. Thank.

+3
source share
6 answers

, Windows SUS , ActiveState ActivePerl ():

perl -nle "print $_, m/updates/i" < C:\Windows\WindowsUpdate.log

, , , .

.

0

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);
                }
            }
        }
+3
+1

- Windows , , . , , .

Windows , .

0

, mdsindzeleta - , , . , Windows XP, . , Vista .

0

, Windows BITS. Bitsadmin.exe Windows. bitsadmin.exe/list, BITS. ( , , )

0

Source: https://habr.com/ru/post/1697387/


All Articles