How to reboot a Windows System using WMI ?
If you know the administrator password of a system that you are authorized to use, you can use this function to reboot it for some automation needs. please do not try this on systems that you are not authorized to use. I have shown only the function definition here. You can use this in a QTP function library.
Sub Reboot_System(ByVal strTargetSystem, ByVal strUserName, ByVal strPassword)Const FORCED_REBOOT = 6
Dim objLocator
Dim objWMIServicewbemImpersonationLevelImpersonate = 3
wbemAuthenticationLevelPktPrivacy = 6
Set objLocator = CreateObject(“WbemScripting.SWbemLocator”)
On Error Resume Next
Set objWMIService = objLocator.ConnectServer _
(strTargetSystem, “root\cimv2″, strUserName, strPassword)
objWMIService.Security_.ImpersonationLevel = wbemImpersonationLevelImpersonate
objWMIService.Security_.AuthenticationLevel = wbemAuthenticationLevelPktPrivacySet colOS = objWMIService.ExecQuery(“SELECT * FROM Win32_OperatingSystem”)
For Each objOS In colOS ‘only one
intReturn = objOS.Win32Shutdown(FORCED_REBOOT)
If intReturn 0 Then
Reporter.ReportEvent micFail, “Error: Unable to reboot.” & VbCrLf & _
“Return code: ” & intReturn
else
Reporter.ReportEvent micPass, “Successfully rebooted” & VbCrLf & _
“Return code: ” & intReturn
End If
NextEnd Sub
No comments yet.
Leave a comment
-
Archives
- June 2009 (1)
- April 2009 (1)
- March 2009 (1)
- August 2008 (5)
- July 2008 (4)
- May 2008 (2)
- April 2008 (3)
- February 2008 (3)
-
Categories
-
RSS
Entries RSS
Comments RSS