Windows automatic update API (2)

Source: Internet
Author: User

CheckArticleIf you haven't read my previous articles, see windows auto update API (1 ).

This article describes how to automatically update the Search Class: updatesearcherclass.

Updatesearcherclass: Search for available updates and installed updates

Search for installed updates:
The queryhistory (INT startindex, int count) method is used. startindex -- starts from the index number (starting from 0) and count -- finds the number of updates (you can enter more than the number of updates installed, for example, 1000, no error occurs. If count is greater than the total number of updates, all sets starting from this index are returned ).
The returned result is of the iupdatehistoryentrycollection collection type. Each element in the collection is of the iupdatehistoryentry2 type, storing the details of each update.

Search for updates that can be installed:
The search (string criteria) method is used. criteria is the filtering item to be searched. You can refer to the iupdate3 type for understanding. For example, iupdate3 has the isinstalled attribute (bool type) and 0 indicates false. You can set this parameter to "isinstalled = 0 ", searches for all updates not installed.Program(Like the where item of an SQL statement), and must be used if two or more items are met.
For example, "type = 1 and isinstalled = 0" indicates searching for uninstalled software updates.

ReferenceCode:

1 Public   Static   Void Autoupdatesearch ()
2 {
3 Try
4 {
5 Wuapilib. updatesearcherclass upsearch =   New Wuapilib. updatesearcherclass ();
6
7 If (Upsearch. Online)
8 {
9 Wuapilib. iupdatehistoryentrycollection uphistoryentcoll = Upsearch. queryhistory ( 0 , 10 );
10
11 Foreach (Wuapilib. iupdatehistoryentry2 uphistoryent In Uphistoryentcoll)
12 {
13 Foreach (Wuapilib. icategory category In Uphistoryent. Categories)
14 {
15 System. Console. writeline ( " Category name: {0} " , Category. Name );
16 System. Console. writeline ( " CATEGORY parent: {0} " , Category. Parent );
17 System. Console. writeline ( " Category Description: {0} " , Category. Description );
18 System. Console. writeline ( " Category Type: {0} " , Category. type );
19 }
20 System. Console. writeline ( " Update title: {0} " , Uphistoryent. Title );
21 System. Console. writeline ( " Description: {0} " , Uphistoryent. Description );
22 System. Console. writeline ( " Supporturl: {0} " , Uphistoryent. supporturl );
23 System. Console. writeline ( " Date: {0} " , Uphistoryent. Date. tolongdatestring ());
24 System. Console. writeline ( "" );
25 }
26 }
27
28 Wuapilib. isearchresult Ressearch = Upsearch. Search ( " Isinstalled = 0 " );
29
30 For ( Int I =   0 ; I < Ressearch. Updates. Count; I ++ )
31 {
32 System. Console. writeline ( " Update title: {0} " , Ressearch. Updates [I]. Title );
33 System. Console. writeline ( " Update type: {0} " , Ressearch. Updates [I]. type. tostring ());
34 System. Console. writeline ( " Max download size: {0} " , Ressearch. Updates [I]. maxdownloadsize );
35 System. Console. writeline ( " Min download size: {0} " , Ressearch. Updates [I]. mindownloadsize );
36 System. Console. writeline ( " Is download: {0} " , Ressearch. Updates [I]. isdownloaded );
37 }
38 }
39 Catch (Exception ex)
40 {
41System. Console. writeline (ex. Message );
42}
43 }

Correct the proxy description in updatesessionclass in the first article. The windows update program can set the proxy user name and password, provided that you enter the user name and password in the IE prompt dialog box, Vista, if you do not enter the information in the IE prompt dialog box, you will be asked to enter the information during the update.

All the code in this article passes the test under Vista, and the DLL is used as wuapi. dll under Vista.

If you do not know how to write data during the development process, you can refer to the class diagram in windows auto update API (1) for a good understanding.

In addition to the configuration information automatically updated, add Exception Handling in other cases.
Especially common cases: if the automatic update service of the PC is disabled, an exception is reported during the search and COM cannot be called.

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.