HEELPBOOK - How to determine the date and time on a remote system using WMI? ####################################### At times, there may be a need to sync your 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. This is a "modified" (and tested) version of the original script posted on haripotter.wordpress.com by HeelpBook Staff. 'Here how to use this function tGetTargetSystemDateTime "computer", "username or DOMAIN\username", "password" Function tGetTargetSystemDateTime(ByVal hostname, ByVal username, ByVal password) strComputer = hostname msgbox(strComputer) 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 colItems = objWMIService.ExecQuery("Select * From Win32_OperatingSystem") For Each objItem in colItems strTime = objItem.LocalDateTime tGetTargetSystemDateTime = WMIDateStringToDate(strTime) msgbox(tGetTargetSystemDateTime) Exit For Next Set colItems = nothing Set objWMIService = nothing Set objLocator = nothing 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 ############ ARTICLE INFO ############# Article Month: July Article Date: 04/07/2012 Permalink: http://heelpbook.altervista.org/2012/how-to-determine-the-date-and-time-on-a-remote-system-using-wmi/ Source: http://haripotter.wordpress.com/2010/12/28/how-to-determine-the-date-and-time-on-a-remote-system-using-wmi/ Language: English View more articles on: http://www.heelpbook.net/ Follow us on Facebook: http://it-it.facebook.com/pages/HeelpBook/100790870008832 Follow us on Twitter: https://twitter.com/#!/HeelpBook Follow us on RSS Feed: http://feeds.feedburner.com/Heelpbook Follow us on Delicious: http://delicious.com/heelpbook