想把net time 的结果存在变量中 winexec(pchar('command.com /c net time \\'+hostname+'>c:\time1.txt'),sw_hide)这个是把域内任何一台机器的时间存到txt文件中,我现在想存在变量中,如何写 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不行就再读这个txt文件,取出时间。 该命令行,读取网络上计算机的时间,耗时,需要等待几秒,才能诗读入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;效果图: 预祝三国成为Delphi版版主 监控局域网内机器的软硬件信息和控制其USB 接口的方法 关于串口通讯 如何动态创建button 当我窗口放大时想放大所有窗口上的控键 如何让EDedit中的整形数居左? 在OpenDialog控件中设置了可以选取多文件,但是打开以后只能打开最后一个文件,如何才能全部打开啊 做报表时预览和打印结果不相符,不知该怎么处理? 怎么用OLE实现与手机的通讯?? 怎样在Delphi中将一个位图对象bmp1按指定比例转换成另一个位图对象bmp2 问下硬盘录像机的二次开发怎么做 TChromium使用问题
再从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;效果图: