【发布时间】:2013-05-01 11:43:02
【问题描述】:
我目前正试图弄清楚,如何在 Windows 8 上将 Windows 更新设置为“让我选择是否安装”而不是“自动安装更新”。
根据Check from .NET if Windows Update is enabled我试过了:
WUApiLib.AutomaticUpdatesClass auc = new WUApiLib.AutomaticUpdatesClass();
// Doing some stuff
但出现以下错误:Interop type 'WUApiLib.AutomaticUpdatesClass' cannot be embedded. Use the applicable interface instead.
The type 'WUApiLib.AutomaticUpdatesClass' has no constructors defined
按照Change windows updates setting with Powershell 中的答案,我做到了:
string subKey = @"SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU";
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(subKey, true))
key.SetValue("AUoptions", 4);
但是注册表中不存在子键导致Reference not set to an instance of an object错误。
Google 的其余结果都描述了如何手动更改此设置,这不是我想要的。
如何以编程方式将 Windows 更新设置为“让我选择是否安装”?
【问题讨论】:
-
为了摆脱互操作错误,在 Visual Studio 中右键单击引用并转到它的属性,然后将“嵌入互操作类型”设置为 false。
-
@Arran 我明白了,现在第一个选项至少有效。很高兴知道,谢谢!现在我终于可以继续工作了:D
标签: c# windows windows-8 windows-update