clopez
asked on
Getting the time
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.
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
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.
NetRemoteTOD is not supported on Win95, only on NT.
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)
This is an Win32API thus it should work with any language which uses windows.
try it.
(looks like delphi)
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?
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?
ASKER
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.
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.
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.
You write some dummy file, after that get Creation's Time of this file, delete file.
What is the return value from NetRemoteTOD()? Perhaps 2184?
ASKER
Ok, here is a dump of a TTimeOfDay record
144780,0,0,21A001E,143C18, 11C,1F0E66 4,12FFC0,7 7F0E68D,7F FDEC00,428 700,C000B
1446E8,0,0,21A001E,143C18, 11C,1F0E66 4,12FFC0,7 7F0E68D,7F FDEC00,428 700,C000B
145790,0,0,21A001E,143C18, 11C,1F0E66 4,12FFC0,7 7F0E68D,7F FDEC00,428 700,C000B
1445C8,0,0,21A001E,143C18, 11C,1F0E66 4,12FFC0,7 7F0E68D,7F FDEC00,428 700,C000B
144538,0,0,21A001E,143C18, 11C,1F0E66 4,12FFC0,7 7F0E68D,7F FDEC00,428 700,C000B
1450D8,0,0,21A001E,143C18, 11C,1F0E66 4,12FFC0,7 7F0E68D,7F FDEC00,428 700,C000B
1449C0,0,0,21A001E,143C18, 11C,1F0E66 4,12FFC0,7 7F0E68D,7F FDEC00,428 700,C000B
144678,0,0,21A001E,143C18, 11C,1F0E66 4,12FFC0,7 7F0E68D,7F FDEC00,428 700,C000B
145280,0,0,21A001E,143C18, 11C,1F0E66 4,12FFC0,7 7F0E68D,7F FDEC00,428 700,C000B
1452C8,0,0,21A001E,143C18, 11C,1F0E66 4,12FFC0,7 7F0E68D,7F FDEC00,428 700,C000B
145310,0,0,21A001E,143C18, 11C,1F0E66 4,12FFC0,7 7F0E68D,7F FDEC00,428 700,C000B
It seemd to me to be the elapsed miliseconds from a fixed time. But I don't get to understand it.
144780,0,0,21A001E,143C18,
1446E8,0,0,21A001E,143C18,
145790,0,0,21A001E,143C18,
1445C8,0,0,21A001E,143C18,
144538,0,0,21A001E,143C18,
1450D8,0,0,21A001E,143C18,
1449C0,0,0,21A001E,143C18,
144678,0,0,21A001E,143C18,
145280,0,0,21A001E,143C18,
1452C8,0,0,21A001E,143C18,
145310,0,0,21A001E,143C18,
It seemd to me to be the elapsed miliseconds from a fixed time. But I don't get to understand it.
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
Really really Sorry K?
Brain
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
.
Time: POINTER of TTimeOfDayInfo; // Check here
.
NetRemoteTOD(@WS, @Time);
Result := (OBJECT of Time); // Check here
ASKER
To Pascal users
the funtion code should be modified to:
function GetServerTime(Server: string): TTimeOfDayInfo;
var
Time: PTimeOfDayInfo;
begin
NetRemoteTOD(PWideChar(Wid eString(WS )), @Time);
//I just learned the WideString shortcut
Result := Time^;
end;
the funtion code should be modified to:
function GetServerTime(Server: string): TTimeOfDayInfo;
var
Time: PTimeOfDayInfo;
begin
NetRemoteTOD(PWideChar(Wid
//I just learned the WideString shortcut
Result := Time^;
end;
>> no need to be so mean though :)
Try getting up 4 times in one night because your child is teeting... Sorry for being harsh.
Try getting up 4 times in one night because your child is teeting... Sorry for being harsh.