3

我试图检查是否启用了 Windows 更新。我在 Windows 7 x64 Ultimate 上添加了对 c:\windows\system32\wuapi.dll 的引用并编写了这段代码

using WUApiLib;
public Boolean IsWindowsUpdateEnabled()
{
    var updates = new AutomaticUpdatesClass();
    return updates.ServiceEnabled;
}

代码无法构建。我收到以下错误:

错误 1 ​​类型“WUApiLib.AutomaticUpdatesClass”没有定义构造函数
错误 2 无法嵌入互操作类型“WUApiLib.AutomaticUpdatesClass”。请改用适用的接口。
错误 3“WUApiLib.AutomaticUpdatesClass”不包含“ServiceEnabled”的定义,并且找不到接受“WUApiLib.AutomaticUpdatesClass”类型的第一个参数的扩展方法“ServiceEnabled”(您是否缺少 using 指令或程序集引用?)

4

2 回答 2

4

In your Visual Studio project References list, find the WUApiLib reference and change its "Embed Interop Types" to "False".

于 2012-10-31T21:02:33.230 回答
3

也许您可以查询注册表以查看?

public string Read(string KeyName)
{
    // Opening the registry key
    RegistryKey rk = baseRegistryKey ;
    // Open a subKey as read-only
    RegistryKey sk1 = rk.OpenSubKey(subKey);
    // If the RegistrySubKey doesn't exist -> (null)
    if ( sk1 == null )
    {
        return null;
    }
    else
    {
        try 
        {
            // If the RegistryKey exists I get its value
            // or null is returned.
            return (string)sk1.GetValue(KeyName.ToUpper());
        }
        catch (Exception e)
        {
            // AAAAAAAAAAARGH, an error!
            ShowErrorMessage(e, "Reading registry " + KeyName.ToUpper());
            return null;
        }
    }
}

来源

以及要查看的位置:

http://www.windowsnetworking.com/articles_tutorials/Registry-Keys-Tweaking-Windows-Update-Part1.html

HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU ...

这些键中的第一个是 AUOptions 键。此 DWORD 值可以指定为 2、3、4 或 5。值 2 表示代理应在下载更新之前通知用户。值 3 表示将自动下载更新并通知用户安装。值 4 表示应根据计划自动下载和安装更新。要使此选项起作用,还必须设置 ScheduledInstallDay 和 ScheduledInstallTime 键。稍后我将更多地讨论这些键。最后,值 5 表示需要自动更新,但可以由最终用户配置。

等等。

虽然如果设置是由组策略完成的,可能会有所不同。

更多信息在这里:http: //support.microsoft.com/kb/328010

于 2012-10-31T20:45:51.807 回答