本文整理自网络,侵删。
unit Unit1;
interface
usesWindows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,StdCtrls;
typeTForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject);private { Private declarations }public { Public declarations }end;
varForm1: TForm1;
implementation
{$R *.DFM}
procedure DeleteMe;varBatchFile: TextFile;BatchFileName: string;ProcessInfo: TProcessInformation;StartUpInfo: TStartupInfo;beginBatchFileName := 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) thenbegin CloseHandle(ProcessInfo.hThread); CloseHandle(ProcessInfo.hProcess);end;end;
procedure TForm1.Button1Click(Sender: TObject);beginDeleteMe;close;end;
end.
相关阅读 >>
Delphi 7zip 示例调用7z.dll 压缩及解压.7z文件
Delphi显示 jpg、png、gif 图片及 gif 动画
更多相关阅读请进入《Delphi》频道 >>