L
lsxysuper
Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm3.shiyanreadtimeClick(Sender: TObject);<br>var<br> myfile:string;<br> prufile:string;<br> f:textfile;<br> // f:file;<br> timetmp:string;<br> timetmp2:string;<br> rehosttime:string;<br> i:integer;<br> len:integer;<br> t:integer;<br> strCmd:string;<br>begin<br><br> myfile:='d:/project2server.exe';<br> prufile:='h:';<br> winexec('cmd /c net use h: //10.20.40.136/super "" /y',sw_shownormal);<br> //将远程机的super共享文件夹映射为 h:<br> sleep(1000);<br> if not fileexists('h:/project2server.exe') then<br> begin<br> winexec('cmd /c copy d:/project2server.exe h:',sw_shownormal);<br> //将本地d:/project2server.exe 复制到 H:<br> sleep(1000);<br> end;<br> //若在C:根目录下有time.txt,则删除此time.txt<br> If FileExists('c:/time.txt') then<br> begin<br> // showmessage('the fiel is exists!');<br> winexec('cmd /c attrib -R c:/time.txt',sw_shownormal); //将文件的只读属性清楚<br> deletefile('c:/time.txt');<br> end;<br> //新建time.txt<br> // tfilestream.Create('c:/time.txt',fmcreate);<br> filecreate('c:/time.txt');<br> sleep(5000);<br> winexec('cmd /c attrib -R c:/time.txt',sw_shownormal);<br> //将文件的只读属性清楚<br> winexec('cmd /c net time //10.20.40.136 >>c:/time.txt',sw_shownormal);<br> //获取远程机的时间 并导入到time.txt中<br> sleep(1000);<br> // winexec('cmd /c net time //10.20.40.64 >>c:/time.txt',sw_shownormal);<br> winexec('cmd /c attrib +R c:/time.txt',sw_shownormal);<br> //将文件的属性设为只读,因为下面的reset(f)要求所对应的文件属性需为只读<br> // filesetattr('c:/time.txt',faReadOnly);<br> // filesetattr('c:/time.txt',1);<br> //get the time form c:/time.txt<br> assignfile(f,'c:/time.txt');//将文件名字符串str赋给文件变量f,程序对文件变量f的操作代替对文件str的操作<br> //打开一个已经存在的磁盘文件,其文件名必须先由assign过程赋给变量f,该文件只能读,指向文件元素的指针指向第一个元素。<br> reset(f); // 此文件只能读<br> //以下是将time.txt中的时间获取回来 并传给at 命令<br> readln(f,timetmp);<br> timetmp2:=timetmp;<br> i:=pos('午 ',timetmp);<br>// len:=length(timetmp);<br> rehosttime:=copy(timetmp,i+3,5);<br> if pos('下',timetmp2)>0 then<br> begin //若为下午,则加上12<br> timetmp2:=copy(rehosttime,1,2);<br> t:=strtoint(timetmp2);<br> t:=t+12;<br> timetmp2:=inttostr(t);<br> // rehosttime:=timetmp2;<br> end; <br> rehosttime:=timetmp2+copy(rehosttime,3,5);<br> showmessage(rehosttime); //测试获到的时间<br> i:=pos(':',rehosttime);<br> timetmp:=copy(rehosttime,i+1,2);<br> t:=strtoint(timetmp);<br> inc(t);<br> timetmp:=inttostr(t);<br> rehosttime:=copy(rehosttime,1,3)+timetmp;<br> showmessage(rehosttime); //测试获到的时间<br> strCmd:='cmd /c at //10.20.40.136 '+rehosttime+'c:/super/project2server.exe';<br> winexec(pchar(strCmd),sw_shownormal);<br> sleep(1000);<br> closefile(f);<br> //end<br> winexec('cmd /c net use h: /d /y',sw_shownormal);<br> //删除映射,准备另一台机子的操作<br>end;<br>我有filecreate('c:/time.txt');新建的time.txt为什么不能用?调度时说我的这个txt正在被另一个程序应用??