C# UpdateSession behind proxy (WUApi.dll)

1

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");
c#
proxy
windows-update
wuapi
asked on Stack Overflow Jan 25, 2021 by Matt M

1 Answer

0

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.

answered on Stack Overflow May 20, 2021 by marsh-wiggle

User contributions licensed under CC BY-SA 3.0