本文整理自网络,侵删。
先介绍一下 MOVEFILEEX 的使用.
移动文件:
MoveFileEx('c:\winnt\system32\xxxx.exe', 'd:\winnt.bak\system32\xxxx.exe',MOVEFILE_REPLACE_EXISTING);
MoveFileEx('c:\winnt\system32\xxxx.exe', 'd:\winnt.bak\system32\xxxx.exe',MOVEFILE_DELAY_UNTIL_REBOOT);
删除文件:
MoveFileEx('c:winnt\system32\xxxx.exe', nil,MOVEFILE_REPLACE_EXISTING);
MoveFileEx('c:winnt\system32\xxxx.exe', nil,MOVEFILE_DELAY_UNTIL_REBOOT);
我们再来看看用什么方法来实现程序自身的更新.
//拷贝副本,更新完删除副本,刚测试好
procedure StartUpdate;
var
vBatchFile: TextFile;
vBatchFileName,vUpdateName: string;
vProcessInfo: TProcessInformation;
vStartUpInfo: TStartupInfo;
begin
vBatchFileName := ExtractFilePath(ParamStr(0)) + '_deleteme.bat';
vUpdateName:=ParamStr(0)+'_Update.exe';
AssignFile(vBatchFile, vBatchFileName);
Rewrite(vBatchFile);
Writeln(vBatchFile, ':try');
Writeln(vBatchFile, 'Copy "'+ParamStr(0) + '" "'+vUpdateName+'"');
Writeln(vBatchFile, vUpdateName + ' /UPDATE');
Writeln(vBatchFile, 'del "' + vUpdateName + '"');
Writeln(vBatchFile,
'if exist "' + vUpdateName + '"' + ' goto try');
Writeln(vBatchFile, 'del %0');
CloseFile(vBatchFile);
FillChar(vStartUpInfo, SizeOf(vStartUpInfo), $00);
vStartUpInfo.dwFlags := STARTF_USESHOWWINDOW;
vStartUpInfo.wShowWindow := SW_HIDE;
if CreateProcess(nil, PChar(vBatchFileName), nil, nil,
False, IDLE_PRIORITY_CLASS, nil, nil, vStartUpInfo,
vProcessInfo) then
begin
CloseHandle(vProcessInfo.hThread);
CloseHandle(vProcessInfo.hProcess);
end;
end;
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/aroc_lo/archive/2008/09/20/2954836.aspx
相关阅读 >>
Delphi用idtcpserver和idtcpclient传输文件
Delphi显示 jpg、png、gif 图片及 gif 动画
Delphi 窗体form的formstyle属性设置为fsstayontop时属性设置不起作用问题探讨。
更多相关阅读请进入《Delphi》频道 >>