Home > Back-end >  Want to put the net time is the result of the variable
Want to put the net time is the result of the variable

Time:09-24

Winexec (pchar (' command.com/c net time \ \ "+ hostname + '& gt; C: \ time1. TXT '), sw_hide)

This is the domain of any machine time to TXT file, I now think there are variable, how to write

CodePudding user response:

Can't read this TXT file, take out time,

CodePudding user response:

The command line, read the computer on the network of time, time consuming, needs to wait for a few seconds, can read the poem MyList,
Again from MyList, decomposition characters, read the variable,
MyList characters:
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
The Current time at \ \ lyhoo is 2016/3/8 20:04:17

The command completed successfully.
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
The code is as follows:
 
Procedure TForm1. Button1Click (Sender: TObject);
Var hostName: string;
MyList: TStringList;
S: a string;
L: integer;
ADateTime: TDateTime;
The begin
MyList:=TStringList. Create;
The hostName:='lyhoo';
Winexec (pchar (' command.com/c net time \ \ "+ hostname + '& gt; C: \ Temp. TXT '), sw_hide);
Sleep (4000);
Memo1. Lines. LoadFromFile (' C: \ Temp. TXT);
MyList. LoadFromFile (' C: \ Temp. TXT);
S:=MyList. Strings [0].
L:=Pos (' is', S);
S:=Copy (S, L + 2, 12);
ShowMessage (S);
ADateTime:=StrToDateTime (S);
MyList. Free;
end;


Effect:
  • Related