Click here to Skip to main content
15,916,941 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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
Posted
Updated 26-Sep-17 9:15am

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

HKEY_LOCAL_MACHINE is not a subkey, and is certainly not in the path of Registry.CurrentUser.
 
Share this answer
 
Comments
Member 10616186 26-Sep-17 5:19am    
Pl confirm is there any option to disable & enable Automatic Windows Update
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.
VB.NET
Dim WSUS As RegistryKey = Registry.LocalMachine.OpenSubKey("Software\Policies\Microsoft\Windows\WindowsUpdate\AU", True)

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[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900