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.

Javier De Pedro
  • 2,219
  • 4
  • 32
  • 49

3 Answers3

6

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".
Tomalak
  • 332,285
  • 67
  • 532
  • 628
Javier De Pedro
  • 2,219
  • 4
  • 32
  • 49
  • 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 Nov 18 '08 at 15:28
  • 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 Nov 18 '08 at 16:28
  • Ops, copy&paste mistake! I don't think not having votes is the problem...I can't not accept my other answer either and it has a vote. If somwbody ever vote this one up it'll check it. – Javier De Pedro Nov 18 '08 at 18:13
2

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

Brian Webster
  • 30,033
  • 48
  • 152
  • 225
Javier De Pedro
  • 2,219
  • 4
  • 32
  • 49
  • 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 Nov 17 '08 at 14:02
  • 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 Nov 17 '08 at 14:23
  • True, but the net effect is the same. – Patrick Cuff Nov 17 '08 at 15:14
  • 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 Nov 18 '08 at 09:58
  • 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 Nov 18 '08 at 12:27
  • (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 Nov 18 '08 at 12:31
  • 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 Nov 18 '08 at 12:33
  • Ok. Understood! Thanks for the explanation...unfortunately I can not grade your comments up! – Javier De Pedro Nov 18 '08 at 13:54
  • 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 Nov 18 '08 at 14:20
1

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
  • 332,285
  • 67
  • 532
  • 628
  • 1
    It should be. Try it. – Tomalak Jun 05 '18 at 11:56
  • 1
    Windows 10 does some crazy, outright hostile stuff when it comes to how Windows update works. It will silently re-enable disabled services, it will prevent services from being disabled, it will go out of its way to force you to install updates if you want or not. Every Windows 10 version comes up with new bullshit. There is a lot of stuff to read on the topic. I can only suggest you read into the topic - I wish you luck, but I can't really give you interactive support on that in the comments. – Tomalak Jun 05 '18 at 12:09
  • 1
    I don't know. And it's possible that any solution you find online only works for a certain Windows 10 version. I have had success in preventing unwanted reboots using https://www.udse.de/en/windows-10-reboot-blocker. Try it out. – Tomalak Jun 05 '18 at 12:24
  • Thank you. In windows home gpedit do not exist so, FYI - 1) https://www.ifixit.com/Guide/How+to+get+gpedit+on+windows+10+Home/102025 2) https://gadgets.ndtv.com/laptops/features/how-to-disable-windows-10-automatic-updates-728049 –  Jun 05 '18 at 12:37