473,373 Members | 1,207 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,373 software developers and data experts.

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 9518
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Don | last post by:
Hi all, With regards to the following, how do I append the datetimestamp to the filenames in the form? The files are processed using the PHP script that follows below. Thanks in advance,...
9
by: Bob Achgill | last post by:
I would like to use the timestamp on files to manage the currency of support files for my VB windows application. In this case I would only put the timestamp of the file in the management database...
6
by: Mike Charney | last post by:
Is there a way to check a files date and time stamp from VBA in access. I have a need check a date stamp on a file that I am importing. Thanks in advance, Mike m charney at dunlap hospital...
3
by: phried1 | last post by:
I have created a form and inserted the following tables: Date Entered Time Entered Date Modified Time Modified Essentially how and where can I have these dates and times recorded so when the...
8
by: Trev | last post by:
Hi Can anyone point me in the right direction here, I would like to open a table in access 2003 by date. I have an asp web page which needs to read data from a table with each days today's date...
4
by: SilentThunderer | last post by:
Hey folks, Let me start out by letting you know what I'm working with. I'm building an application in VB 2005 that is basically a userform that employees can use to "Clock in". The form...
6
by: trytobreak | last post by:
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...
16
by: W. eWatson | last post by:
Are there some date and time comparison functions that would compare, say, Is 10/05/05 later than 09/22/02? (or 02/09/22 format, yy/mm/dd) Is 02/11/07 the same as 02/11/07? Is 14:05:18 after...
29
by: WannabePrgmr | last post by:
I am trying to display total numbers of data in a textbox, "Textbox200" on a form "Master", but I only want to display current daily data. I currently get the data from: Me.Text200 = DCount("",...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.