winexec(pchar('command.com /c net time \\'+hostname+'>c:\time1.txt'),sw_hide)这个是把域内任何一台机器的时间存到txt文件中,我现在想存在变量中,如何写

解决方案 »

  1.   

    不行就再读这个txt文件,取出时间。
      

  2.   

    该命令行,读取网络上计算机的时间,耗时,需要等待几秒,才能诗读入MyList中,
    再从MyList中,分解字符,读入变量中。
     MyList中的字符:
    --------------------------------------------------------------
    Current time at \\lyhoo is 2016/3/8 20:04:17The 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;效果图: