热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

从vbscript启用/禁用windows-update-Enable/disablewindows-updatefromavbscript

Ineedtodisablewindows-updateservicefrommyinstallation.Ialreadyusevbscripttodosomestu

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.

我需要从我的安装中禁用windows-update服务。我已经使用Vbscript做了一些事情,所以我想在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!

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

Thanks.

3 个解决方案

#1


7  

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

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

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

方法1:防止“自动更新”服务在计算机启动时自动启动。

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)

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

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.

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

You can do both of these things through the GUI:

您可以通过GUI执行这两项操作:

  • Method 1: Administrative Tools\Services\Automatic Updates, change "Startup type" from "Automatic" to "Disabled".
  • 方法1:管理工具\服务\自动更新,将“启动类型”从“自动”更改为“已禁用”。

  • Method 2: Control Panel\Automatic Updates, select "Turn off Automatic Updates".
  • 方法2:控制面板\自动更新,选择“关闭自动更新”。

#2


2  

If you want to use Vbscript, use WMI:

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

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

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

Easier would be the use of sc.exe:

更容易使用sc.exe:

sc config wuauserv start=auto

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

以下是sc.exe可以执行的操作的摘录:

C:\>sc config
Modifies a service entry in the registry and Service Database.
SYNTAX:
sc  config [service name]  ...
CONFIG OPTIONS:
NOTE: The option name includes the equal sign.
 type= 
 start= 
 error= 
 binPath= 
 group= 
 tag= 
 depend= 
 obj= 
 DisplayName= 
 password= 

#3


2  

Thank you Tomalak.

谢谢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

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


推荐阅读
author-avatar
mobiledu2502868653
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有