haripotter’s technorati

Just another WordPress.com weblog

How to determine the date and time on a remote system using WMI ?

How to determine the date and time on a remote system using WMI ?

At times, there may be a need to sync your QTP client systems time with a remote system before executing a test. There are otherways to sync windows system time such as NTP servers. Below is one way to getting the target system time using WMI. Setting the local system time will be another function that I’ll post later.


Function tGetTargetSystemDateTime(ByVal hostname, ByVal username, ByVal password)

Reporter.Filter=3
tGetTargetSystemDateTime = ""
wbemImpersonationLevelImpersonate = 3
wbemAuthenticationLevelPktPrivacy = 6

Set objLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = objLocator.ConnectServer _
(hostname, "root\cimv2",username ,password)

objWMIService.Security_.ImpersonationLevel = wbemImpersonationLevelImpersonate
objWMIService.Security_.AuthenticationLevel = wbemAuthenticationLevelPktPrivacy
'Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery("Select * From Win32_OperatingSystem")

For Each objItem in colItems
strTime = objItem.LocalDateTime
tGetTargetSystemDateTime = WMIDateStringToDate(strTime)
Exit For
Next

Set colItems = nothing
Set objWMIService = nothing
Set objLocator = nothing

Reporter.Filter=0
End Function


Private Function WMIDateStringToDate(ByVal strTime)
WMIDateStringToDate = CDate(Mid(strTime, 5, 2) & "/" & _
Mid(strTime, 7, 2) & "/" & Left(strTime, 4) _
& " " & Mid (strTime, 9, 2) & ":" & _
Mid(strTime, 11, 2) & ":" & Mid(strTime, _
13, 2))
End Function

Advertisement

December 28, 2010 - Posted by | HP Quality Center and QTP

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.