Solved

VB script to compare net time

Posted on 2011-02-22
5
544 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Unlike scripting languages such as C# where a semi-colon is used to indicate the end of a command, Microsoft's VBScript language relies on line breaks to determine when a command begins and ends. As you can imagine, this quickly results in messy cod…
Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now