Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用Windows Update代理API检查WSUS服务器_C#_Wuapi - Fatal编程技术网

C# 使用Windows Update代理API检查WSUS服务器

C# 使用Windows Update代理API检查WSUS服务器,c#,wuapi,C#,Wuapi,我试图确定WSUS是否使用Windows Update代理API管理当前计算机。目前,我的代码查看所有在Windows Update代理中注册的服务 private static bool IsManagedByWSUS(WUApiNativeMethods.IUpdateSession3 session) { WUApiNativeMethods.IUpdateServiceManager serviceManager = session.CreateUpdat

我试图确定WSUS是否使用Windows Update代理API管理当前计算机。目前,我的代码查看所有在Windows Update代理中注册的服务

    private static bool IsManagedByWSUS(WUApiNativeMethods.IUpdateSession3 session)
    {
        WUApiNativeMethods.IUpdateServiceManager serviceManager = session.CreateUpdateServiceManager();
        WUApiNativeMethods.IUpdateServiceCollection services = serviceManager.Services;
        foreach (WUApiNativeMethods.IUpdateService service in services)
        {
            // Indicates whether the service is registered with automatic updates
            var registeredWithAu = service.IsRegisteredWithAU();
            // Indicates whether the service is a managed service
            var isManaged = service.IsManaged();
            var name = service.Name().ToLower();
            if (registeredWithAu &&
                isManaged &&
                name.Contains("windows server update service"))
            {
                return true;
            }
        }
        return false;
    }
问题是,我不知道检查名称是否可靠。我看到IUpdateService对象上有一个作为guid的服务id字段。我测试了几个盒子,看起来总是3da21691-e39d-4da6-8a4b-b43877bcb1b7


如何可靠地检查WSU?

您可以检查注册表文件:HKLM\SOFTWARE\Policys\Microsoft\Windows\WindowsUpdate

shell命令:

reg query "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate"

如何安装Windows Update代理API?