问题描述
嗨,我正在尝试制作一个 C# 应用程序,它可以检查缺少的 Windows 更新。当用户登录时,我可以让我的代码工作,因为这似乎解决了我的代理身份验证问题,但我希望它在用户登录之前在启动时运行。下面是我的代码,它从 Visual Studio 或当我构建它并在另一台 PC 上运行但是当我将它设置为在启动时运行并重新启动 PC 时,我得到的只是“System.Runtime.InteropServices.COMException (0x80240438): Exception from HRESULT: 0x80240438 at WUApiLib.IUpdateSearcher.Search(字符串条件)"
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");
解决方法
您的代理可能集成了 Active Directory,不接受此类登录。
您可以尝试创建一个在所需用户的上下文中运行的计划任务并在那里启动您的代码。