|
reboot.vbs
----------------------------------------------------------
Option Explicit
Dim strComputer
Dim strUser
Dim strPassword
Dim oWshShell
Dim objSWbemLocator
Dim objSWbemServices
Dim colOperatingSystems
Dim objOperatingSystem
Set oWshShell = CreateObject("Wscript.Shell")
strComputer = UCase(InputBox("Please enter the Computer Name: "))
strUser = InputBox("Please enter the Administrator Name: ")
strPassword = InputBox("Please enter the administrator password: ")
On Error Resume Next
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objSWbemServices = objSWbemLocator.ConnectServer _
(strComputer, "root\cimv2", strUser, strPassword)
If Err.Number <> 0 Then
oWshShell.Popup "WMI Connection was not successful. " & Chr(13) &_
Err.Description, 10, Err.Source & " on " & strComputer, 48
Else
Set colOperatingSystems = objSWbemServices.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
ObjOperatingSystem.Reboot()
Next
If Err.Number <> 0 Then
oWshShell.Popup "Reboot operation was not successful. " & Chr(13) _
& Err.Description, 10, Err.Source & " on " & strComputer, 48
Else
oWshShell.Popup strComputer & " is restarting.", 10, "Successful.", 64
End If
End If
-----------------------------------------------------------------
如上所示
我試著改了很久,但是還是改不出來
我的盲點是,vbs中的
On Error Resume Next
If Err.Number
Err.Description
感謝 |
|