Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find date and time on server 1

Status
Not open for further replies.

Leonard

Programmer
Jan 26, 1999
10
US
Can someone email me or help us in locating Visual Basic Code to determine the date and time on a sever from a local workstation.

Workstation name = "Jane"
Server Name = "Emily"

Any suggestions?

We just want to capture the complete date and time on the server to a variable.
Thank you
Leonard
 
There has been a number of solutions to this posted on this forum, amongst them thread222-60790

I notice that although you've asked several questions, you haven't acknowledged any of the answers given, nor marked any as helpful/expert. In order to get the best from the forum try reading faq222-2244, which will give guidance on searching, how to phrase questions and general forum etiquette. Regarding email answers, see para 12 in the faq.


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
There is a FAQ on this too: faq222-1065

Chip H.
 
Or, if you just hate it when people just won't answer the question with a simple line of code, try this:

v = Shell("net time /set /yes", vbHide)
 
mastersword:

>if you just hate it when people just won't answer the question with a simple line of code

in defence of johnwm and chiph they did answer the question indirectly, and a search of tek-tips would have turned these links up!

i also fail to see how your code will work given a workstationa nd server name!!!!

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
The Great Date Debate Thread222-368305
File Formats Galore @ or
 

MasterSword,

To use net time the way you are on a domain there must be a time server setup if not you will get an error message like...

[tt]
Error 3912: Windows was unable to locate a time server. Try again, specifying the name of the server you would like to synchronize with.
[/tt]

so to say...

>If you only have one server, it must work

is an incorrect statement.

I have verified this on my home domain with running only my NT 4.0 server (which by the way is my domain controler) or just my Win 2k Server and since my domain controler was down for this test I recieved two different error messages. The first was while my NT was shutting down...

[tt]
Error 53: The computer name specified in the network path cannot be located. Make sure you are specifying the computer name correctly, or try again later when the remote computer is available.
[/tt]

and

[tt]
Error 6118: The computer(s) sharing resources in this workgroup cannot be located. The computer(s) might have been restarted. Wait a few minutes, and then try again. If the problem persists, make sure your network-adapter settings are correct.
[/tt]

So it seems that if you just hate it when people just won't answer the question with a simple line of code there must be a reason why.

Leonard Good Luck

 
I have 11 computers operating on Windows 98 connected to 1 Windows 2000 Professional Family and that shelled statement works PERFECTLY. That's how I keep the company's time clock in check. Whether or not it works for you is beyond me.

-- Never underestimate the power of the GOTO statement.
 

So then you agree that it is not a simple line of code that will give Leonard the answer! And, I can tell you why it does not work for me....

I do not have a time server set up! Whereas you do! And not all networks will have a time server set up, so there must be a reason why not always a "simple" line of code will work.

 
>If you only have one server

And if I don't? The question sure doesn't make that claim, so we can't make that assumption. Ok, maybe we could change the code to:

v = Shell(NET TIME \\<SERVERNAME> /SET /Y, vbHide)

But, whether we use this version or yours, this would:
a) have the nasty side effect of changing our workstation's time
b) not return the answer in a VB variable

If either a) or b) come in to effect then we haven't answered the original question, which specifically states: &quot;We just want to capture the complete date and time on the server to a variable&quot;

Sure, we could capture the workstation's current time and date, run your simple line of code, retrieve the new settings into VB variables through the Time and Date functions, and then set our system back to the original settings through another shell command (remembering to add on the time it took to actually run the code, if we're really fussy). Indeed, this might be an acceptable solution for the original questioner - but it sure as heck is no longno longer &quot;a simple line of code&quot;...

Alternatively, we could remove the /SET /Y, which solves a) - but we still fall foul of b), and need to develop a strategy for getting the time string the command returns into a VB variable. Again, this would no longer be &quot;a simple line of code&quot;...

The reason this site retains threads, has a search engine (and there is worked planned to improve it, as I'll grant it has limitations at the moment), and a FAQ repository is to allow us to refer back to them rather than typing in the same answers over and over again.
 
Hey Hey Hey. What's with all the testy attitudes?

It works for me, and I don't have a...&quot;time server&quot;, or whatever you called it set up. All it does is find the local server and match time. What's the big deal?

And if you don't have just one server, I'm sorry, I just *assumed* that they guy asking the question only had one; and since my method works for me, (and we only have one,) I continued in my *assumption* and figured that would work for him too.

Oh, and I made the comment about not just telling the answer in one line of code because I *assumed* I had the answer in one like of code.

-- Never underestimate the power of the GOTO statement.
 
My two cents:

When the computers I look after log on (this is on an NT4 server-based network) they execute a logon script, one part of which sets the time to match the server's, so that all computers have the same time.

In this case using Time would return pretty much the correct time give or take a few milliseconds.

Alternatively, couldn't one write the output of the shelled time to a text file and then read that in? Not awfully sophisticated, I know, but then it's only about ten lines of code...


Andy
&quot;Logic is invincible because in order to combat logic it is necessary to use logic.&quot; -- Pierre Boutroux
&quot;Why does my program keep showing error messages every time something goes wrong?&quot;
 
Yep, that would be one of the possible strategies I referred to. Low-tech, sure, but certainly workable and not to be dismissed.
 
For what it's worth: Machines that are part of an AD domain have their clocks set at login. The reason is that Active Directory needs to know what time it is so that it can do replication across remote links and not have duplicates or dropped objects.

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top