Windows automatic update API (4)

Source: Internet
Author: User
Previous articles Article This article describes how to view update software and how to download and install updates.

Before downloading, you must first determine whether there are any updates, and then determine which updates to download. Of course, you can also download all updates (this time is similar to the XP pirated update Patch to avoid downloading and installing ).

The updatesearcherclass, isearchresult, updatedownloaderclass, and updateinstallerclass classes are involved.
Start the search at the download point using the instance of updatesearcherclass and put the search result in isearchresult.
An updatedownloaderclass object is instantiated and the search result is returned to the updatedownloaderclass instance object.
Call the download method of the instance to start downloading. This method is not an asynchronous method, so the following method will be executed until the download is complete.
Installation:
Instantiate an updateinstallerclass class, give the search result to the instance, and then call the install method to install it.

In the investigation, the machine environment is vista. When the automatic update of the system is enabled and downloaded, use your ownProgramAfter the update, the system's automatic update program will not respond.

ReferenceCode:

1 Public   Void Updatedownload ()
2 {
3 Wuapilib. updatesearcherclass upsearch =   New Wuapilib. updatesearcherclass ();
4
5 If (Upsearch. Online)
6 {
7 Wuapilib. isearchresult Ressearch = Upsearch. Search ( " Isinstalled = 0 " );
8
9 Wuapilib. updatedownloaderclass updownload =   New Wuapilib. updatedownloaderclass ();
10 Wuapilib. updateinstallerclass upinstall =   New Wuapilib. updateinstallerclass ();
11
12 Updownload. Updates = Ressearch. updates;
13
14 System. Windows. Forms. MessageBox. Show ( " Start download " );
15
16 If (Updownload. Updates. Count >   0 )
17 {
18Updownload. Download ();
19}
20
21 System. Windows. Forms. MessageBox. Show ( " Start install " );
22
23 Upinstall. Updates = Updownload. updates;
24
25 If (Upinstall. Updates. Count >   0 )
26 {
27Upinstall. Install ();
28}
29
30 System. Windows. Forms. MessageBox. Show ( " Install OK " );
31 }
32 }

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.