views:

5867

answers:

3

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.

+1  A: 

If you want to use VBScript, use WMI:

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

Look into the documentation of the WMI Win32_Service Class to find out what else might be doable.

Easier would be the use of sc.exe:

sc config wuauserv start=auto

Here is an excerpt of what sc.exe can do:

C:\>sc config
Modifies a service entry in the registry and Service Database.
SYNTAX:
sc <server> config [service name] <option1> <option2>...
CONFIG OPTIONS:
NOTE: The option name includes the equal sign.
 type= <own|share|interact|kernel|filesys|rec|adapt>
 start= <boot|system|auto|demand|disabled>
 error= <normal|severe|critical|ignore>
 binPath= <BinaryPathName>
 group= <LoadOrderGroup>
 tag= <yes|no>
 depend= <Dependencies(separated by / (forward slash))>
 obj= <AccountName|ObjectName>
 DisplayName= <display name>
 password= <password>
Tomalak
+2  A: 

Thank you Tomalak.

I also found that:

Const SCHEDULED_INSTALLATION = 1

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

objSettings.NotificationLevel = SCHEDULED_INSTALLATION
objSettings.Save

This is the link: http://www.microsoft.com/technet/scriptcenter/resources/tales/sg0705.mspx

So now I have another question. Which solution is better?

Javier De Pedro
I'd say your solution is "better" because it's a little more readable (I'd add a comment that SCHEDULED_INSTALLATION = 1 means "disabled").
Patrick Cuff
This code does not disable the auto update service, but something *entirely different*. This code is better in the same way as black shoes are better than brown jackets.
Tomalak
True, but the net effect is the same.
Patrick Cuff
Ok. So could you explain me what this code do??? As you can see I don't know how this works and I'd like to.
Javier De Pedro
The code above changes the "Automatic Updates" service from "Automatic" to "Turn off Automatic Updates". The code below tells the "Automatic Updates" service to start automatically when the machine boots (change "Automatic" to "Disabled" below to stop the service and prvent it from starting)
Patrick Cuff
(continued) In both cases you won't get automatic updates. With the code below (revised to "Disabled") the service won't start while with the code above the service is still running, just not doing anything.
Patrick Cuff
You can do both of these things through the GUI. Code above = Control Panel\Automatic Updates, select "Turn off Automatic Updates". Code below = Administrative Tools\Services\Automatic Updates, change "Startup type" from "Automatic" to "Disabled".
Patrick Cuff
Ok. Understood! Thanks for the explanation...unfortunately I can not grade your comments up!
Javier De Pedro
No problem, you caught your own fish anyway?You could edit your answer with Tomalak's response below, along with the explanation of what each does, and accept that as the answer.
Patrick Cuff
+5  A: 

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".
Javier De Pedro
Anyway I can not set this answer as the accepted one...I suppose it's because is mine and I am the one who make the question.
Javier De Pedro
Javier, maybe you can't accept this unti it gets an up vote. Also, you have the descirption of Answer 1 and Answer 2 backwords ;)
Patrick Cuff
Javier De Pedro
+1. One more and you'll get the "Self Learner" badge. ;-)
Tomalak