Solved

VB script to compare net time

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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
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…

626 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