Enabling and Disabling Microsoft Update in Windows 7 via Script

The Windows Update Feature in Windows 7 allows administrators to configure it to either service Windows only or to extend it to other products from Microsoft Update. In most cases, Windows Update is used by end-users only with no need to automate or script this process, since larger organisations usually utilise other means like System Center Configuration Manager to keep their systems up to date.

image

In some cases, however, you actually do get into the position where you want (or need) to change this setting for your end users, so scripting it can come in handy.

How to do this is documented here: msdn.microsoft.com/en-us/library/aa826676(VS.85).aspx and can be achieved via a simple script:

Set ServiceManager = CreateObject("Microsoft.Update.ServiceManager")
ServiceManager.ClientApplicationID = "My App"
'add the Microsoft Update Service by GUID
Set NewUpdateService = ServiceManager.AddService2("7971f918-a847-4430-9279-4a52d1efe18d",7,"")

The reverse step is also possible with a simple alteration:

Set ServiceManager = CreateObject("Microsoft.Update.ServiceManager")
ServiceManager.ClientApplicationID = "My App"
'remove the Microsoft Update Service by GUID
ServiceManager.RemoveService("7971f918-a847-4430-9279-4a52d1efe18d")