VBS-管理计算几则实例
1.禁用与启用系统还原禁用:
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\default")
Set objItem = objWMIService.Get("SystemRestore")
errResults = objItem.Disable("")
Wscript.Echo errResults
启用:
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\default")
Set objItem = objWMIService.Get("SystemRestore")
errResults = objItem.Enable("")
Wscript.Echo errResults
2.关闭重起本地计算机
关闭计算机:
Set colOperatingSystems = GetObject("winmgmts:{(Shutdown)}").ExecQuery("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
ObjOperatingSystem.Win32Shutdown(1)
Next
重起计算机:
strComputer = "atl-dc-01"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(Shutdown)}!\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
ObjOperatingSystem.Reboot()
Next
3.在本机删除安装软件
删除软件:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSoftware = objWMIService.ExecQuery _
("Select * from Win32_Product Where Name = 'Personnel database'")
For Each objSoftware in colSoftware
objSoftware.Uninstall()
Next
安装软件:
Const ALL_USERS = True
Set objService = GetObject("winmgmts:")
Set objSoftware = objService.Get("Win32_Product")
errReturn = objSoftware.Install("c:\scripts\database.msi", , ALL_USERS)
4.在远程计算机上安装软件
Const wbemImpersonationLevelDelegate = 4
Set objWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objConnection = objwbemLocator.ConnectServer _
("WebServer", "root\cimv2", "fabrikam\administrator", _
"password", , "kerberos:WebServer")
objConnection.Security_.ImpersonationLevel = wbemImpersonationLevelDelegate
Set objSoftware = objConnection.Get("Win32_Product")
errReturn = objSoftware.Install("\\atl-dc-02\scripts\1561_lab.msi",,True)
Wscript.Echo errReturn yct07
大哥
你不用那么勤奋吧???
把我整个bolg都搬过来了..... [quote]原帖由 [i]冰心痴[/i] 于 2007-6-30 10:14 PM 发表 [url=http://www.dreams8.com/redirect.php?goto=findpost&pid=7246&ptid=1694][img]http://www.dreams8.com/images/common/back.gif[/img][/url]
yct07
大哥
你不用那么勤奋吧???
把我整个bolg都搬过来了..... [/quote]
你的BOLG?
在哪里?
我怎么没有看见过? 我的blog....
[url]http://hi.baidu.com/[/url]冰心痴 你的BLOG还是别的地方来的,昏。共享一下又何妨?
页:
[1]