我正在尝试构建一个代码,通过按钮上的clink来禁用或启用Windows更新 [英] I am trying to built a code which disables or enabled windows update by clink on the button

查看:78
本文介绍了我正在尝试构建一个代码,通过按钮上的clink来禁用或启用Windows更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到了错误

对象引用没有设置为对象的实例。

WSUS.SetValue(NoAutoUpdate,0)



我尝试过:



Private Sub Button3_Click(发送者为对象,e为EventArgs)处理Button3.Click



Dim WSUS As RegistryKey = Registry.CurrentUser.OpenSubKey(HKEY_LOCAL_MACHINE \Software \POLicies \ Microsoft \ Windows \ Windows \更新AU,False)

WSUS.SetValue(NoAutoUpdate,0)

MsgBox(Windows Update现已启用,vbOKOnly)



End Sub

I got the error
Object reference not set to an instance of an object.
WSUS.SetValue("NoAutoUpdate", 0)

What I have tried:

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click

Dim WSUS As RegistryKey = Registry.CurrentUser.OpenSubKey("HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\WindowsUpdate\AU", False)
WSUS.SetValue("NoAutoUpdate", 0)
MsgBox("Windows Update is now Enabled", vbOKOnly)

End Sub

推荐答案

Registry.CurrentUser.OpenSubKey("HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\WindowsUpdate\AU", False)



HKEY_LOCAL_MACHINE 不是一个子项,并且肯定不在 Registry.CurrentUser 的路径中。


HKEY_LOCAL_MACHINE is not a subkey, and is certainly not in the path of Registry.CurrentUser.


正如解决方案#1中所指出的, HKEY_LOCAL_MACHINE 是一个注册表配置单元。它不是 HKEY_CURRENT_USER 的子键。



如果你想写密钥,那么你需要将 True 传递给可写参数。

As pointed out in solution #1, HKEY_LOCAL_MACHINE is a registry hive. It is not a sub-key of HKEY_CURRENT_USER.

If you want to write to the key, then you need to pass True to the writable parameter.
Dim WSUS As RegistryKey = Registry.LocalMachine.OpenSubKey("Software\Policies\Microsoft\Windows\WindowsUpdate\AU", True)



注意:由于您尝试修改计算机配置,因此您的应用程序需要升级。向您的应用程序添加清单,并将 requestedExecutionLevel 设置为 requireAdministrator



让您的应用程序UAC意识到 [ ^ ]


NB: Since you're trying to modify the machine configuration, your application will need to run elevated. Add a manifest to your application, and set requestedExecutionLevel to requireAdministrator.

Making Your Application UAC Aware[^]


这篇关于我正在尝试构建一个代码,通过按钮上的clink来禁用或启用Windows更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆