3

我需要从我的安装中禁用 windows-update 服务。我已经使用 vbscript 来做一些事情,所以我想用 vbscript 来做。

我对 vbscript(或任何其他脚本语言)的了解非常有限,所以......有人可以帮我解决这个问题吗?我会很感激的!

谢谢。

4

3 回答 3

6

感谢 Tomalak 和 Patrick Cuff。我真的很感谢你的帮助。我认为这可能是一个很好且完整的答案。

方法一:防止“自动更新”服务在机器启动时自动启动。

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

方法2:将“自动更新”配置从“自动”更改为“关闭自动更新”。(MSDN 列出了其他 NotificationLevel 常量

Const AU_DISABLED = 1

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

objSettings.NotificationLevel = AU_DISABLED
objSettings.Save

在这两种情况下,您都不会获得自动更新。使用方法 1 将无法启动,而使用方法 2 服务仍在运行,只是没有执行任何操作。

您可以通过 GUI 完成这两件事:

  • 方法一:管理工具\服务\自动更新,将“启动类型”从“自动”改为“禁用”。
  • 方法二:控制面板\自动更新,选择“关闭自动更新”。
于 2008-11-18T15:25:04.900 回答
2

谢谢托马拉克。

我还发现:

Const SCHEDULED_INSTALLATION = 1

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

objSettings.NotificationLevel = SCHEDULED_INSTALLATION
objSettings.Save

这是链接: http: //www.microsoft.com/technet/scriptcenter/resources/tales/sg0705.mspx

于 2008-11-17T13:53:14.103 回答
1

如果要使用 VBScript,请使用 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

查看WMI Win32_Service 类的文档以找出其他可行的方法。

更容易使用sc.exe

sc config wuauserv start=auto

以下是sc.exe可以做什么的摘录:

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>
于 2008-11-17T13:48:23.830 回答