C# UpdateSession behind proxy (WUApi.dll)

202 views Asked by At

Hi I'm trying to make a C# app that can check for missing windows updates. I can get my code to work when a user is logged in as that seems to sort out my proxy authentication issues but I want it to run on startup, before a user logs in. Below is my code, it runs fine from visual studio or when I build it and run on another PC but when I set it to run on startup and restart the PC all I get is "System.Runtime.InteropServices.COMException (0x80240438): Exception from HRESULT: 0x80240438 at WUApiLib.IUpdateSearcher.Search(String criteria)"

            IUpdateSession uSession = new UpdateSession();

            uSession.WebProxy.AutoDetect = false;
            uSession.WebProxy.Address = "http://ipAddress:port";
            uSession.WebProxy.UserName = @"Domain\user";
            string password = "password";
            uSession.WebProxy.SetPassword(password);

            IUpdateSearcher uSearcher = uSession.CreateUpdateSearcher();
            ISearchResult uResult = uSearcher.Search("IsInstalled=0");
1

There are 1 answers

0
marsh-wiggle On

Your proxy is probably Active Directory integrated and does not accept this kind of login.

You may try to create a scheduled task which runs in the context of the wanted user and start your code there.