winexec(pchar('command.com /c net time \\'+hostname+'>c:\time1.txt'),sw_hide)
這個是把域內任何一臺機器的時間存到txt檔案中,我現在想存在變數中,如何寫
uj5u.com熱心網友回復:
不行就再讀這個txt檔案,取出時間。uj5u.com熱心網友回復:
該命令列,讀取網路上計算機的時間,耗時,需要等待幾秒,才能詩讀入MyList中,再從MyList中,分解字符,讀入變數中。
MyList中的字符:
--------------------------------------------------------------
Current time at \\lyhoo is 2016/3/8 20:04:17
The command completed successfully.
--------------------------------------------------------------
代碼如下:
procedure TForm1.Button1Click(Sender: TObject);
var hostName:string;
MyList:TStringList;
S:string;
L:integer;
aDateTime:TDateTime;
begin
MyList:=TStringList.Create;
hostName:='lyhoo';
winexec(pchar('command.com /c net time \\'+hostname+'>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,19);
showMessage(S);
aDateTime:=StrToDateTime(S);
MyList.Free;
end;
效果圖:
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/71339.html
標籤:網絡通信/分布式開發
上一篇:問下硬碟錄像機的二次開發怎么做
