我目前正在尝试弄清楚如何在 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 的其余结果都描述了如何手动更改此设置,这不是我要找的。p>
如何以编程方式将 Windows 更新设置为“让我选择是否安装”?
最佳答案
感谢Arran ,我设法朝着正确的方向迈出了一步:
Well to get rid of the interop error, right-click the reference in Visual Studio and go it's properties, and turn "Embed Interop Types" to false.
现在我不再遇到互操作错误,我设法得出结论;这是代码:
// using WUApiLib;
AutomaticUpdatesClass auc = new AutomaticUpdatesClass();
auc.Settings.NotificationLevel = AutomaticUpdatesNotificationLevel.aunlNotifyBeforeInstallation;
auc.Settings.Save();
关于c# - 如何以编程方式更改 Windows 更新选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16317510/