[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Getting the time

Posted on 1998-12-29
12
Medium Priority
?
725 Views
Last Modified: 2013-12-03
Does anyone know how te get the system time in a remote machine.  I know there is a funciton in the netapi32 called NetRemoteTOD which is supposed to be the one, but it doesnt work for me.  My actual call to the funtion is:

unit rtime;

interface

uses windows;

type
  TNetAPIStatus = DWord;

   TTimeOfDayInfo = record
      tod_elapsedt,
         tod_msecs,
         tod_hours,
         tod_mins,
         tod_secs,
         tod_hunds: DWord;
      tod_timezone: LongInt;
      tod_tinterval,
         tod_day,
         tod_month,
         tod_year,
         tod_weekday: DWord;
   end;

   PTimeOfDayInfo = ^TTimeOfDayInfo;

function NetRemoteTOD(UncServerName: LPWSTR;
   BufferPtr: PTimeOfDayInfo): TNetAPIStatus; stdcall;

function GetServerTime(Server: string): TTimeOfDayInfo;

const
   netapi32 = 'netapi32.dll';

implementation

function NetRemoteTOD;
   external netapi32 name 'NetRemoteTOD';

function GetServerTime(Server: string): TTimeOfDayInfo;

var
   Time: TTimeOfDayInfo;
   WS: array[0..255] of Char;

begin
   StringToWideChar(Server, @WS, SizeOf(WS));
   NetRemoteTOD(@WS, @Time);
   Result := Time;
end;

end.

Well I always get the same time (The funtion is supposed to work for a local machine).  I suppose it needs to have the net instaled.

TIA.
0
Comment
Question by:clopez
[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
  • 4
  • 3
  • 2
  • +2
12 Comments
 
LVL 11

Expert Comment

by:alexo
ID: 1417803
NetRemoteTOD is not supported on Win95, only on NT.
0
 
LVL 1

Expert Comment

by:The_Brain
ID: 1417804
GetLocalTime(SYSTEMTIME lpSystemTime ); LpSystemTime is a variable it can be x.

This is an Win32API thus it should work with any language which uses windows.

try it.

(looks like delphi)
0
 
LVL 11

Expert Comment

by:alexo
ID: 1417805
Say, The_Brain, do you really read the question before you rush in to tock it?
clopes explicitly said "Does anyone know how te get the system time in a remote machine".  GetLocalTime() got its name for a reason.
This is not the first time you lock a question with a completely irrelevant answer.  Why don't you slow down, read the questions more carefully and do more research?
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

Author Comment

by:clopez
ID: 1417806
1.- As alexo sayd.  There is no problem getting the time in the local machine.  The problem in getting it in a remote machine.  

2.- I lloks like delphi and It is delphi.

3.- I know it only works in NT.  But I don't care if any one gives a solution that works in any other operating system and NT.

4.- I've been testing.  It may be a problem on how to understan TimeOfDayInfo.
0
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 1417807
There is simple way, if you can write file to remote machine.
You write some dummy file, after that get Creation's Time of this file, delete file.
0
 
LVL 11

Expert Comment

by:alexo
ID: 1417808
What is the return value from NetRemoteTOD()?  Perhaps 2184?
0
 

Author Comment

by:clopez
ID: 1417809
Ok, here is a dump of a TTimeOfDay record

144780,0,0,21A001E,143C18,11C,1F0E664,12FFC0,77F0E68D,7FFDEC00,428700,C000B
1446E8,0,0,21A001E,143C18,11C,1F0E664,12FFC0,77F0E68D,7FFDEC00,428700,C000B
145790,0,0,21A001E,143C18,11C,1F0E664,12FFC0,77F0E68D,7FFDEC00,428700,C000B
1445C8,0,0,21A001E,143C18,11C,1F0E664,12FFC0,77F0E68D,7FFDEC00,428700,C000B
144538,0,0,21A001E,143C18,11C,1F0E664,12FFC0,77F0E68D,7FFDEC00,428700,C000B
1450D8,0,0,21A001E,143C18,11C,1F0E664,12FFC0,77F0E68D,7FFDEC00,428700,C000B
1449C0,0,0,21A001E,143C18,11C,1F0E664,12FFC0,77F0E68D,7FFDEC00,428700,C000B
144678,0,0,21A001E,143C18,11C,1F0E664,12FFC0,77F0E68D,7FFDEC00,428700,C000B
145280,0,0,21A001E,143C18,11C,1F0E664,12FFC0,77F0E68D,7FFDEC00,428700,C000B
1452C8,0,0,21A001E,143C18,11C,1F0E664,12FFC0,77F0E68D,7FFDEC00,428700,C000B
145310,0,0,21A001E,143C18,11C,1F0E664,12FFC0,77F0E68D,7FFDEC00,428700,C000B

It seemd to me to be the elapsed miliseconds from a fixed time.  But I don't get to understand it.
0
 
LVL 1

Expert Comment

by:The_Brain
ID: 1417810
sorry Alexo, I am a bit on the tired side, so I did probably mis read the question. (no need to be so mean though :)

Really really Sorry K?
Brain
0
 
LVL 15

Accepted Solution

by:
NickRepin earned 400 total points
ID: 1417811
As you can see from the my sample, the last parameter for the NetRemoteTOD is NOT the pointer to TIME struct, but POINTER TO POINTER to time struct.
In other words, this function allocates internal buffer, and copies the pointer to it to your pointer passed by reference.

Here is the working sample for C++ console app
#include <windows.h>
#include <lmcons.h>
#include <lmremutl.h>
#include <iostream.h>

// a.exe [<server>]
void main(int argc,char* argv[])
{
   wchar_t serverName[MAX_COMPUTERNAME_LENGTH+1];
   if(argc>1)
      mbstowcs(serverName,argv[1],strlen(argv[1])+1);
   PTIME_OF_DAY_INFO t; // Pointer to struct, but NOT the struct!
   NET_API_STATUS r=NetRemoteTOD(argc>1 ? serverName : 0,(LPBYTE*)(&t));
   if(r) {
      cout<<"Error!"<<endl;
      return;
   }
   cout<<"Date="<<(t->tod_year)<<"/"<<(t->tod_month)<<"/"<<
      (t->tod_day)<<endl;
   cout<<"Time="<<(t->tod_hours)<<":"<<(t->tod_mins)<<":"<<
      (t->tod_secs)<<endl;
}
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 1417812
I don't remember how to declare pointer to var in Pascal, but

.
   Time: POINTER of TTimeOfDayInfo; // Check here
.
   NetRemoteTOD(@WS, @Time);
   Result :=  (OBJECT of Time);    // Check here

0
 

Author Comment

by:clopez
ID: 1417813
To Pascal users

the funtion code should be modified to:

function GetServerTime(Server: string): TTimeOfDayInfo;

    var
       Time: PTimeOfDayInfo;

    begin
       NetRemoteTOD(PWideChar(WideString(WS)), @Time);  
//I just learned the WideString shortcut
       Result := Time^;
    end;

0
 
LVL 11

Expert Comment

by:alexo
ID: 1417814
>> no need to be so mean though :)
Try getting up 4 times in one night because your child is teeting...  Sorry for being harsh.
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

656 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