none
Windows Update Agent in Windows 7 RRS feed

  • Question

  • I have a desktop app that installs windows updates using the Windows Update Agent, problem I have is that it works on XP machines but when I run on a windows 7 machine I get this error

    "Exception from HRESULT: 0x80240044

    Interop.WUApiLib

       at WUApiLib.UpdateDownloaderClass.Download()
       at CheckSystemUpTime.Form1.btnInstallUpdates_Click(Object sender, EventArgs e)



    WUApiLib.IDownloadResult Download()"

     

    Here is my complete code for running the updates

     //Install Updates
              UpdateSessionClass uSession = new UpdateSessionClass();
              IUpdateSearcher uSearcher = uSession.CreateUpdateSearcher();
    
              ISearchResult uResult = uSearcher.Search("IsAssigned=1 and IsInstalled=0");
              UpdateDownloader downloader = uSession.CreateUpdateDownloader();
              downloader.Updates = uResult.Updates;
              downloader.Download();
    
              UpdateCollection updatesToInstall = new UpdateCollection();
              foreach (IUpdate update in uResult.Updates)
              {
                if (update.IsDownloaded)
                  updatesToInstall.Add(update);
              }
    
              IUpdateInstaller installer = uSession.CreateUpdateInstaller();
              installer.Updates = updatesToInstall;
    
              IInstallationResult installationRes = installer.Install();
    
    
             
    
    

    Friday, October 15, 2010 6:54 PM

Answers

  •  

    Since Windows Vista introduced User Account Control (UAC), even you logged on as a user who is a member of Administrator, by default, you don't have all administrator's privileges enabled. When you perform an operation which requires administrator privilege, you need to elevate yourself to administrator.

     

    As Sheng mentioned, you may run the application as administrator, you can

     

    either right-click the application icon, select Run as administrator,

     

    or add an Application Manifest File (app.manifest) to your project, modify app.manifest to:

     

    <?xml version="1.0" encoding="utf-8"?>

    <asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

      <assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>

      <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">

        <security>

          <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">

            <!-- UAC Manifest Options

                If you want to change the Windows User Account Control level replace the

                requestedExecutionLevel node with one of the following.

     

            <requestedExecutionLevel  level="asInvoker" uiAccess="false" />

            <requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />

            <requestedExecutionLevel  level="highestAvailable" uiAccess="false" />

     

                If you want to utilize File and Registry Virtualization for backward

                compatibility then delete the requestedExecutionLevel node.

            -->

            <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

          </requestedPrivileges>

        </security>

      </trustInfo>

    </asmv1:assembly>


    Sincerely,
    Eric
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by CLProgrammer2 Thursday, October 21, 2010 2:18 PM
    Monday, October 18, 2010 2:08 AM

All replies

  • That's WU_E_PER_MACHINE_UPDATE_ACCESS_DENIED

    Error message would be 

    Only administrators can perform this operation on per-machine updates.

    So make sure you run the app as administrator.



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    Friday, October 15, 2010 7:16 PM
  •  

    Since Windows Vista introduced User Account Control (UAC), even you logged on as a user who is a member of Administrator, by default, you don't have all administrator's privileges enabled. When you perform an operation which requires administrator privilege, you need to elevate yourself to administrator.

     

    As Sheng mentioned, you may run the application as administrator, you can

     

    either right-click the application icon, select Run as administrator,

     

    or add an Application Manifest File (app.manifest) to your project, modify app.manifest to:

     

    <?xml version="1.0" encoding="utf-8"?>

    <asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

      <assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>

      <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">

        <security>

          <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">

            <!-- UAC Manifest Options

                If you want to change the Windows User Account Control level replace the

                requestedExecutionLevel node with one of the following.

     

            <requestedExecutionLevel  level="asInvoker" uiAccess="false" />

            <requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />

            <requestedExecutionLevel  level="highestAvailable" uiAccess="false" />

     

                If you want to utilize File and Registry Virtualization for backward

                compatibility then delete the requestedExecutionLevel node.

            -->

            <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

          </requestedPrivileges>

        </security>

      </trustInfo>

    </asmv1:assembly>


    Sincerely,
    Eric
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by CLProgrammer2 Thursday, October 21, 2010 2:18 PM
    Monday, October 18, 2010 2:08 AM
  • The app manifest file works but only for admin users.  Can anything be done to get it to work for limited users?

     

    Thursday, October 21, 2010 2:18 PM