Windows automatic update API (1)

Source: Internet
Author: User

I wrote about the firewall settings under Vista a few days ago. Today I think all the firewalls have corresponding APIs. Is there any corresponding API for automatic update? What is the difference between Vista and XP? Start a day's investigation with this question.

After checking a lot of information, find that Windows Update must be operated through Windows Update agent (wua ).
In Vista and XP, The wuapi. dll can be found (windows \ system32). The strange thing is that the dll version in Vista is 6.0, while that in XP is 5.8. I don't know where to change it, I roughly checked the main classes and found that nothing was changed. Is it just an internal function adjustment?

To operate the corresponding Windows Update classes, you must understand the relationship between them ,:

It is never hard to find that automaticupdatesclass is only a set class that is automatically updated. All automatically updated classes use updatesessionclass.

Get all automatically updated settings and how to change the settings:
Instantiate an automaticupdatesclass class and then access its settings attribute, which contains:
Notificationlevel: automatic update action (automatic/invalid/download/Download notification after notification), enumeration type
Scheduledinstallationday: the number of automatically downloaded files per week (from Monday to Sunday). Enumeration type
Scheduledinstallationtime: Automatic download time (from)

Can be directly modified
Automaticupdatesnotificationlevel attributes and scheduledinstallationday and scheduledinstallationtime
Call the Save method of iautomaticupdatessettings after setting.
The iautomaticupdatessettings instance is obtained through the settings attribute of the automaticupdatesclass object.

In the automaticupdatesclass class, you can call the enableservice method to start the automatic update service. Only after the automatic update service is started, you can read the automatic update settings to obtain the updated content from the MS website. In general, the automatic update service is set to automatic start.

You can alsoProgramAfter the service is started, it is automatically set to automatic start (whether you are manual or invalid). Ms does not provide a way to stop the service.

After the service is started, you can use the following three methods:
Detectnow: Start update
Pause: Pause updates
Resume: resumes updates.

ReferenceCode:

1 Public   Static   Void Autoupdatesetting ()
2 {
3 System. Console. writeline ( " AutoUpdate imformation: " );
4
5 Wuapilib. automaticupdatesclass updatecls =   New Wuapilib. automaticupdatesclass ();
6
7 // Show update dialog:
8 Updatecls. showsettingsdialog ();
9
10 Wuapilib. iautomaticupdatessettings upsettings = Updatecls. settings;
11
12 // Show update setting -- Notification level
13 // Aunlnotconfigured = 0
14 // Aunldisabled = 1
15 // Aunlpolicybeforedownload = 2
16 // Aunlpolicybeforeinstallation = 3
17 // Aunlscheduledinstallation = 4
18 System. Console. writeline ( " Notification level: {0} " , Upsetication. icationicationlevel. tostring ());
19
20 If (Upsetication. icationicationlevel = Wuapilib. automaticupdatesnotificationlevel. aunlscheduledinstallation)
21 {
22 // Scheduledinstallationday:
23 // Ausideveryday = 0,
24 // Ausideverysunday = 1,
25 // Ausideverymonday = 2,
26 // Ausideverytuesday = 3,
27 // Ausideverywednesday = 4,
28 // Ausideverythursday = 5,
29 // Ausideveryfriday = 6,
30 // Ausideverysaturday = 7,
31
32 // Scheduledinstallationtime: 0-23
33 System. Console. writeline ( " Update schedule time: {0 },{ 1} " ,
34 Upsettings. scheduledinstallationday. tostring (),
35 Upsettings. scheduledinstallationtime. tostring ());
36 }
37
38 Upsetication. icationicationlevel = Wuapilib. automaticupdatesnotificationlevel. aunlpolicybeforedownload;
39 Upsettings. Save ();
40
41 If (Updatecls. serviceenabled)
42 {
43 System. Console. writeline ( " Update Service State: {0} " , Updatecls. serviceenabled. tostring ());
44 // Updatecls. enableservice ();
45 System. Console. writeline ( " Detectnow " );
46 Updatecls. detectnow ();
47
48 Thread. Sleep ( 10000 );
49 System. Console. writeline ( " Pause " );
50 Updatecls. Pause ();
51
52 Thread. Sleep ( 10000 );
53 System. Console. writeline ( " Resume " );
54 Updatecls. Resume ();
55 }
56
57 System. Console. writeline ();
58 }

As we all know, the automatic update settings in the control panel do not have the proxy option. Does automatic update support proxy?
Of course, yes. The automatic update will set the connection according to the proxy in the IE browser. But what about the username and password required for the current server?
This can only be set through the program. The updatesessionclass class provides this function.

After the class is instantiated, the instance of the webproxyclass class is obtained by accessing the WebProxy attribute of the class.
You can set two attributes of the webproxyclass class and call a method.
Address: proxy address
Username: User Name
Setpassword (string strpassword): Set the password

Reference code: 1 Public   Static   Void Autoupdatesession ()
2 {
3 Wuapilib. updatesessionclass upsesscls =   New Wuapilib. updatesessionclass ();
4
5 System. Console. writeline ( " Update session: {0} " , Upsesscls. clientapplicationid );
6
7 Wuapilib. webproxyclass WebProxy = (Wuapilib. webproxyclass) upsesscls. WebProxy;
8
9 WebProxy. Address =   @" ********* " ;
10 WebProxy. Username =   " ******* " ;
11 WebProxy. setpassword ( " ****** " );
12
13 System. Console. writeline ( " WebProxy address: {0} " , WebProxy. Address );
14 System. Console. writeline ( " WebProxy autodetect: {0} " , WebProxy. autodetect );
15 System. Console. writeline ( " WebProxy Username: {0} " , WebProxy. username );
16 }

When I found out here, I wanted to develop a software program, so I could perform more operations on my own, for automatic updates.
If you have any good ideas, please tell me, thank you ~~~.

If there is an error in the text, I hope to correct it.

China does not have good information in this regard. You can refer to the MS msdn.
Refer:
Interfaces (Windows)
Using the Windows Update agent API (Windows)
Windows Update agent Object Model (Windows)

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.