gpt4 book ai didi

c# - 如何使用 C# 可靠地检查是否启用了 Windows 更新?

转载 作者:行者123 更新时间:2023-11-30 14:34:55 29 4
gpt4 key购买 nike

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

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

代码构建失败。我收到以下错误:

Error 1 The type 'WUApiLib.AutomaticUpdatesClass' has no constructors defined
Error 2 Interop type 'WUApiLib.AutomaticUpdatesClass' cannot be embedded. Use the applicable interface instead.
Error 3 'WUApiLib.AutomaticUpdatesClass' does not contain a definition for 'ServiceEnabled' and no extension method 'ServiceEnabled' accepting a first argument of type 'WUApiLib.AutomaticUpdatesClass' could be found (are you missing a using directive or an assembly reference?)

最佳答案

在您的 Visual Studio 项目引用列表中,找到 WUApiLib 引用并将其“嵌入互操作类型”更改为“假”。

关于c# - 如何使用 C# 可靠地检查是否启用了 Windows 更新?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13166978/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com