Solved

VB script to compare net time

Posted on 2011-02-22
5
554 Views
Last Modified: 2012-05-11
I am working on a script to compare the output of net time for several servers. The issue I am having is gathering just the information I need from the output string For example the output of server peach is

Current time at \\peach is 2/22/2011 9:55:32 AM

The command completed successfully.

Now I need to comapre just the time portion of this output. How do I isolate it?
0
Comment
Question by:Frog_1337
  • 3
5 Comments
 
LVL 12

Expert Comment

by:prashanthd
ID: 34953978
Can you give more details on the requirement as to how you will compare etc?
0
 
LVL 12

Expert Comment

by:prashanthd
ID: 34953979
Can you give more details on the requirement as to how you will compare etc?
0
 
LVL 12

Expert Comment

by:prashanthd
ID: 34953982
Can you give more details on the requirement as to how you will compare etc?
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 34957762
From the output, just take it from " is ":
strOutput = "Current time at \\peach is 2/22/2011 9:55:32 AM"
dteTime = CDate(Mid(strOutput, InStr(strOutput, " is ") + 4))

Regards,

Rob.
0
 
LVL 3

Accepted Solution

by:
sam0x01 earned 500 total points
ID: 34959644
This will run net time and extract the date and time and convert it to the Date and output both strDate and dteDate.

I have noticed that the net time command responds with the US date format no matter what the regional settings are which could be an issue for countries that use different regional settings.

ie when run on 6/12/2011will likely record the date as 12/6/2011.


Set objWShell = CreateObject("WScript.Shell") 
Set objCmd = objWShell.Exec("net time \\127.0.0.1") 
strResult = objCmd.StdOut.Readall() 
set objCmd = nothing: Set objWShell = nothing 

numStartDateTime = Instr(1, strResult,"is", vbTextCompare)+2
numEndDateTime = Instr(1, strResult, "The", vbTextCompare)-5
strDateTime= Left (strResult, numEndDateTime)
strDateTime= Right(strDateTime, Len(strDateTime)-numStartDateTime)
dteTime=CDate(strDateTime)
WScript.Echo """" & strDateTime & """ """ & dteTime & """"

Open in new window

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question