Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB script to compare net time

Posted on 2011-02-22
5
Medium Priority
?
560 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

722 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