我目前想弄清楚,如何将Windows更新设置为“让我选择是否安装”,而不是在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 2013-05-01 11:48:41
@Arran我看到了,现在第一个选项至少起作用。很高兴知道,谢谢!现在我终于可以恢复工作了:D – Nolonar 2013-05-01 11:51:12