Windows automatic update API (3)

Source: Internet
Author: User

The previous article describes how to search for software installed and not installed. The uninstalled software is obtained through the update website of Ms. But if the client is offline and you want to know which software is missing from your machine, how can this problem be implemented? The following describes how to search for software not installed offline.

Prepare a cab file, which is a collection of all patch packages provided by MS for all operating systems. It is recommended to update the cab file on a regular basis, because the MS patch is released at any time.
: Wsusscan. Cab

Classes used: updatesessionclass, updateservicemanagerclass, iupdateservice2, iupdatesearcher2, isearchresult, iupdate3

Create an updatesessionclass and use this class instance to create a search class.
Create an updateservicemanagerclass class, register a service by calling the addscanpackageservice method of this class, specify the scanned cab package, and return the iupdateservice2 instance. The last parameter of this method refers to the updateoperation Enumeration type (install/uninstall)
Call the createupdatesearcher method to create an iupdatesearcher2 instance through an updatesessionclass instance.

Key:
Specify the serverselection attribute of the iupdatesearcher2 instance. This attribute indicates whether to search for all, windowsupdate, or others, and default includes all.
The serviceid of the specified iupdatesearcher2 instance is equal to the serviceid of the iupdateservice2 instance.
The search method is called.

ReferenceCode:

1 Public List < Unupdatedentry > Scanofflineupdates ()
2 {
3 List < Unupdatedentry > List =   New List < Unupdatedentry > ();
4
5 Wuapilib. updatesessionclass upsession =   New Wuapilib. updatesessionclass ();
6 Wuapilib. updateservicemanagerclass upservicemanager =   New Wuapilib. updateservicemanagerclass ();
7 Wuapilib. iupdateservice2 upservice = (Wuapilib. iupdateservice2) upservicemanager. addscanpackageservice ( " Offline Sync service " , @" D: \ wsusscan. Cab " , 0 );
8
9 Wuapilib. iupdatesearcher2 upsearch = (Wuapilib. iupdatesearcher2) upsession. createupdatesearcher ();
10
11 Upsearch. serverselection = Wuapilib. serverselection. ssdefault;
12
13 Upsearch. serviceid = Upservice. serviceid;
14
15 Wuapilib. isearchresult Ressearch = Upsearch. Search ( " Isinstalled = 0 " );
16
17 Foreach (Wuapilib. iupdate3 update In Ressearch. Updates)
18 {
19 Unupdatedentry entry =   New Unupdatedentry ();
20 Entry. Title = Update. title;
21 Entry. Type = Update. type. tostring ();
22 Entry. maxsize = Update. maxdownloadsize;
23 Entry. minsize = Update. mindownloadsize;
24 Entry. Download = Update. isdownloaded;
25
26 List. Add (entry );
27 }
28
29 Return List;
30 }

Here, I put the obtained information into a list <t> set and bind it to the data source control.

In the next article, I will explain how to select one or more patches for download and installation. The above code passes the test in XP and Vista. If your machine has code, please call the WebProxy attribute of updatesessionclass.
Address attribute: used to set the proxy address
Void promptforcredentials (Object parentwindow, String title) method: winformProgramCall: Specifies the title of the parent form and the pop-up form. After this method is called, a dialog box is displayed to allow the user to enter the user name and password.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.