Vbscript 通过VBS重新启动计算机
我需要一种更简单/更有效的方法通过VBS重新启动计算机。下面的代码是到目前为止我所拥有的一个示例。是否有比SendKeys方法更有效的方法重新启动其他方法Vbscript 通过VBS重新启动计算机,vbscript,Vbscript,我需要一种更简单/更有效的方法通过VBS重新启动计算机。下面的代码是到目前为止我所拥有的一个示例。是否有比SendKeys方法更有效的方法重新启动其他方法 Option Explicit Dim obj set obj= creatobject("wscript.shell") obj.run "CMD" wscript.sleep 300 obj.SendKeys "shutdown /r" obj.SendKeys "{ENTER}" obj.
Option Explicit
Dim obj
set obj= creatobject("wscript.shell")
obj.run "CMD"
wscript.sleep 300
obj.SendKeys "shutdown /r"
obj.SendKeys "{ENTER}"
obj.SendKeys "exit"
obj.SendKeys "{ENTER}"
wscript.quit
谢谢您可以使用winmgmts,此脚本接受计算机名的参数,但很容易更改以供您使用
If Wscript.Arguments.Count = 0 Then
strComputer = inputbox("Enter a computer name to Restart","Enter computer name")
if strComputer = "" then wscript.quit
Else
strCOmputer = Wscript.Arguments.Item(0)
End If
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
它会起作用的
Set OpSysSet = GetObject("winmgmts:{authenticationlevel=Pkt," _
& "(Shutdown)}").ExecQuery("select * from Win32_OperatingSystem where "_
& "Primary=true")
for each OpSys in OpSysSet
retVal = OpSys.Reboot()
next
为什么
SendKeys
?只需运行可执行文件<代码>CreateObject(“WScript.Shell”)。运行“shutdown.exe/r”