469,600 Members | 2,444 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,600 developers. It's quick & easy.

How to get the current date/time stamp from a network computer?

Hi All,

I am a network administrator in a fairly large software company and I
would like to write myself a small utility, which would connect (one
by one) to all machines on the network and get their current date and
time stamps.

This is mostly because of coming DST changes and having hundreds of
machines on the network, I don't want to connect remotely to every and
each server to see if the time is correct.

Is there any function or command in VB.NET which lets me grab a
current date/time from a network computer?

Please let me know, you could save me a lot of time :)

Thanks,
JK

Oct 29 '07 #1
6 9220
On Oct 29, 8:46 am, trytobr...@gmail.com wrote:
Hi All,

I am a network administrator in a fairly large software company and I
would like to write myself a small utility, which would connect (one
by one) to all machines on the network and get their current date and
time stamps.

This is mostly because of coming DST changes and having hundreds of
machines on the network, I don't want to connect remotely to every and
each server to see if the time is correct.

Is there any function or command in VB.NET which lets me grab a
current date/time from a network computer?

Please let me know, you could save me a lot of time :)

Thanks,
JK
Well... Assuming NT based machines you could always automate the NET
TIME command.

--
Tom Shelton

Oct 29 '07 #2
On Oct 29, 8:46 am, trytobr...@gmail.com wrote:
Hi All,

I am a network administrator in a fairly large software company and I
would like to write myself a small utility, which would connect (one
by one) to all machines on the network and get their current date and
time stamps.

This is mostly because of coming DST changes and having hundreds of
machines on the network, I don't want to connect remotely to every and
each server to see if the time is correct.

Is there any function or command in VB.NET which lets me grab a
current date/time from a network computer?

Please let me know, you could save me a lot of time :)

Thanks,
JK
Reply, in case you want to use the API for this, you can use
NetRemoteTOD.

--
Tom Shelton

Oct 29 '07 #3
Funnily I said something along the same lines on the c# group :)

----- Original Message -----
From: "Brendon Bezuidenhout" <ab****@bezfamily.net>
Newsgroups: microsoft.public.dotnet.languages.csharp
Sent: Monday, October 29, 2007 4:00 PM
Subject: Re: How to get the current date/time stamp from a network computer?

Hey,

No offence but if you are the network admin would it not be easier to send
a
batch down on next login and force the Internet Time to reset to the most
current "real time"? I admit I might be going off at a tangent slightly
but
it could do the job and save you tons of time having to write a tiny app
to
do the work windows can on it's own - IF you tell it *grin*...

Something like this in a .bat file
<code>
net stop w32time
w32tm /unregister [ignore error message]
w32tm /unregister [enter a second time]
w32tm /register
reg add hklm\system\currentcontrolset\services\w32time\par ameters\ /v
NtpServer /t reg_sz /d time.nist.gov /f
net start w32time
</code>

I think there is/was an error with time.windows.com or another of the time
prefix ones as they don't/won't accept requests in TIME format anymore -
nist.gov will cause no issues.

HTH
Brendon

"Tom Shelton" <to*********@comcast.netwrote in message
news:11**********************@t8g2000prg.googlegro ups.com...
On Oct 29, 8:46 am, trytobr...@gmail.com wrote:
>Hi All,

I am a network administrator in a fairly large software company and I
would like to write myself a small utility, which would connect (one
by one) to all machines on the network and get their current date and
time stamps.

This is mostly because of coming DST changes and having hundreds of
machines on the network, I don't want to connect remotely to every and
each server to see if the time is correct.

Is there any function or command in VB.NET which lets me grab a
current date/time from a network computer?

Please let me know, you could save me a lot of time :)

Thanks,
JK

Well... Assuming NT based machines you could always automate the NET
TIME command.

--
Tom Shelton
Oct 29 '07 #4
Hi,

I was really looking for an answer to my problem...
Problem is, you see, that we are not syncing (for various reasons)
with time servers.
So I need to know if the time is correct some other way and this would
be the best.
Anyhow, is someone here capable to answer the question? :)
Can I remotely get the network computer's time and date?

And if so, could someone tell me how?

Oct 29 '07 #5
Sorry, I have overlooked...
I am researching now the NetRemoteTOD. Quite interesting.
Thanks, lets see if I can get it to work.

Oct 29 '07 #6
On Oct 29, 2:03 pm, trytobr...@gmail.com wrote:
Sorry, I have overlooked...
I am researching now the NetRemoteTOD. Quite interesting.
Thanks, lets see if I can get it to work.
Here is some c# code, I wrote to try out this function. You could
convert this to vb, and modify it to loop through a list of machines
- either from a file, or enumerating the machines on the network.

class Program
{
static void Main ( string[] args )
{
IntPtr handle = IntPtr.Zero;
if (NetRemoteTOD ( "\\\\yournetworkpc", ref handle ) ==
NERR_Success)
{
TIME_OF_DAY_INFO time =
(TIME_OF_DAY_INFO)Marshal.PtrToStructure ( handle, typeof
( TIME_OF_DAY_INFO ) );

// new date time. The hours are in utc, so you hae to
use the timezone
// offset.
DateTime dt = new DateTime ( (int)time.tod_year,
(int)time.tod_month, (int)time.tod_day, (int)(time.tod_hours -
(time.tod_timezone / 60)), (int)time.tod_mins, (int)time.tod_secs );

Console.WriteLine ( dt );

uint result = NetApiBufferFree ( handle );
if (result != NERR_Success)
Console.WriteLine ( "Memory cleanup failed: {0}",
result );
}
}

private const uint NERR_Success = 0;

/// <summary>
/// Free the buffer allocated by the NetRemoteTOD function
/// </summary>
/// <param name="Buffer">pointer to the buffer</param>
/// <returns>NERR_Success on success, else the system error
code.</returns>
[DllImport("netapi32.dll", SetLastError=false)]
private static extern uint NetApiBufferFree ( IntPtr Buffer );

[DllImport ( "netapi32.dll", CharSet = CharSet.Unicode,
SetLastError = false )]
private static extern uint NetRemoteTOD ( string
UncServerName, ref IntPtr BufferPtr );

[StructLayout(LayoutKind.Sequential)]
private struct TIME_OF_DAY_INFO
{
public uint tod_elapsedt;
public uint tod_msecs;
public uint tod_hours;
public uint tod_mins;
public uint tod_secs;
public uint tod_hunds;
public uint tod_timezone;
public uint tod_tinterval;
public uint tod_day;
public uint tod_month;
public uint tod_year;
public uint tod_weekday;
}
}

Oct 29 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Don | last post: by
9 posts views Thread by Bob Achgill | last post: by
6 posts views Thread by Mike Charney | last post: by
16 posts views Thread by W. eWatson | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.