This is a mirror of official site: http://jasper-net.blogspot.com/

Install Windows Updates using C# & WUAPI

| Wednesday, February 9, 2011
This document explains how to get the windows updates available for the current machine and selectively install them, using c#.

Overview
This document explains how to get the windows updates available for the current machine
and selectively install them, using c#.

Requirement
Perform Windows Updates customized installation using c# and Windows Update API Library.
This will provide centralized command over customized installation of updates, patches, KB for
Windows.
EX: If particular updates are not to be installed on some machines, in such cases, we can
configure our custom update application to ignore those updates, using this approach.

Benefits
1.  Exclusive command over the updates installed over a network of systems.
2.  Easy to develop and support, using .NET
3.  Simple API approach

References Required
Add reference to the c:\WINDOWS\system32\wuapi.dll file. This is the API library for Window
Update system.
Write the below import statement

using WUApiLib;
using System.Management;


Coding

Now, we need to search the Microsoft updates for this machine;

UpdateSessionClass uSession = new UpdateSessionClass();
IUpdateSearcher uSearcher = uSession.CreateUpdateSearcher();
ISearchResult uResult = uSearcher.Search("IsInstalled=0 and
Type='Software'");

All the updates found will be now populated into the uResult collection object, which can be
accessed using the below foreach loop

foreach (IUpdate update in uResult.Updates)
{
      Console.WriteLine(update.Title);
}

Note that, we have only found the updates available for this machine, but haven’t
downloaded them yet.

You can iterate the available updates to select only the required updates and add then to an
UpdateCollection class which can be assigned to the below UpdateDownloader class so as to
download them

Now we have to create an UpdateDownloader class object to download the updates, as below

UpdateDownloader downloader = uSession.CreateUpdateDownloader();
downloader.Updates = uResult.Updates;
downloader.Download();


Read more: EggCafe

Posted via email from Jasper-net

2 comments:

Anonymous said...

tfhs longchamp bags RdkWcm 5353
longchamp outlet mxib http://www.longchampbagspurse.com/ longchamp outlet

Ranjt ovpuca longchamp handbags 2065
longchamp outlet yttv http://www.longchamphandbagsusa.com/ longchamp outlet

gcxy longchamp sale FfuBq paris s 8233
longchamp outlet ontp http://www.longchampsalepurse.com/ longchamp outlet

Ibxna ulstwg longchamp le pliage nlv0243
longchamp outlet vebf http://www.longchamplepliageus.com/ longchamp outlet

Lbrdg longchamp phtevb
Wwg longchamp outlet iv onu longchamp paris gta
Ripwl longchamp eulj long champ zd longchamp sale quyeek
Hwo longchamp outlet jn lai longchamp paris gyn
Ryf longchamp le pliage pj longchamp iqs longchamp le pliage onb
Rrc longchamp outlet nx em longchamp bags w longchamp paris sbp

Anonymous said...

excb longchamp bags LcbFxt 6122
longchamp outlet pkav http://www.longchampbagspurse.com/ longchamp outlet

Xfsas voyjoo longchamp handbags 5079
longchamp outlet dgju http://www.longchamphandbagsusa.com/ longchamp outlet

lhwe longchamp sale AmlSx paris g 2178
longchamp outlet damt http://www.longchampsalepurse.com/ longchamp outlet

Wpgfc ihtwbn longchamp le pliage sgs6333
longchamp outlet afyb http://www.longchamplepliageus.com/ longchamp outlet

Tlhjp longchamp cuezec
Zqw longchamp outlet cs bmg longchamp paris nvy
Sypxy longchamp gkhs long champ kx longchamp sale ybqcsg
Dal longchamp outlet vh myl longchamp paris xpn
Zwb longchamp le pliage wj longchamp iyq longchamp le pliage mtt
Dyp longchamp outlet cd vm longchamp bags c longchamp paris xed