当前位置: 首页 > 技术文档, 资源共享 > 正文

在制作自动更新时,需要删除自己来替换新程序并运行! 这段代码就很有用了! 调用: 其实也可以用读写ini的方式 […]

在制作自动更新时,需要删除自己来替换新程序并运行!
这段代码就很有用了!

procedure DeleteMe;
var
BatchFile: TextFile;
BatchFileName: string;
ProcessInfo: TProcessInformation;
StartUpInfo: TStartupInfo;
begin
BatchFileName := ExtractFilePath(ParamStr(0)) + '_deleteme.bat';
AssignFile(BatchFile, BatchFileName);
Rewrite(BatchFile);
Writeln(BatchFile, ':try');
Writeln(BatchFile, 'del "' + ParamStr(0) + '"');
Writeln(BatchFile,
'if exist "' + ParamStr(0) + '"' + ' goto try');
Writeln(BatchFile, 'del %0');
CloseFile(BatchFile);
FillChar(StartUpInfo, SizeOf(StartUpInfo), $00);
StartUpInfo.dwFlags := STARTF_USESHOWWINDOW;
StartUpInfo.wShowWindow := SW_HIDE;
if CreateProcess(nil, PChar(BatchFileName), nil, nil,
False, IDLE_PRIORITY_CLASS, nil, nil, StartUpInfo,
ProcessInfo) then
begin
CloseHandle(ProcessInfo.hThread);
CloseHandle(ProcessInfo.hProcess);
end;

调用:

DeleteMe

其实也可以用读写ini的方式来自我删除,兼容性更好!

本文固定链接: https://blog.meyisi.cn/jishu/66.html | 么意思博客
标签:

delphi 程序自我删除代码:等您坐沙发呢!

发表评论

快捷键:Ctrl+Enter