Enable/disable windows-update from a vbscript

vbscriptwindows-services

I need to disable windows-update service from my installation. I already use vbscript to do some stuff so I would like to do it in vbscript.

My knowledge of vbscript (or any other script language) is very limited so…can anybody help me out with that? I'll really appreciate it!

Thanks.

Best Answer

Thanks Tomalak and Patrick Cuff. I really appreciate your help. I think this could be a good and complete answer.

Method 1: prevents the "Automatic Updates" service from starting automatically when the machine boots.

strComputer = "."  'could be any computer, not just the local one '
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colServiceList = objWMIService.ExecQuery _
("Select * from Win32_Service where Name = 'wuauserv'")

For Each objService in colServiceList
  objService.ChangeStartMode("Disabled")
Next

Method 2: changes the "Automatic Updates" configuration from "Automatic" to "Turn off Automatic Updates". (MSDN lists the other NotificationLevel constants)

Const AU_DISABLED = 1

Set objAutoUpdate = CreateObject("Microsoft.Update.AutoUpdate")
Set objSettings = objAutoUpdate.Settings

objSettings.NotificationLevel = AU_DISABLED
objSettings.Save

In both cases you won't get automatic updates. With method 1 won't start while with method 2 the service is still running, just not doing anything.

You can do both of these things through the GUI:

  • Method 1: Administrative Tools\Services\Automatic Updates, change "Startup type" from "Automatic" to "Disabled".
  • Method 2: Control Panel\Automatic Updates, select "Turn off Automatic Updates".
Related Topic