delphi 程序自刪除函數 DeleteMe 德州行業網
- procedure DeleteMe;
- var
- BatchFile: TextFile;
- BatchFileName: string;
- ProcessInfo: TProcessInformation;
- StartUpInfo: TStartupInfo;
- begin
- BatchFileName := ExtractFilePath(ParamStr(0)) + '$$del$$.bat';
- AssignFile(BatchFile, BatchFileName);
- Rewrite(BatchFile);
- Writeln(BatchFile, ':try');
- Writeln(BatchFile, 'del "' + GetShortName(ParamStr(0)) + '"');
- Writeln(BatchFile, 'if exist "' + GetShortName(ParamStr(0)) + '"' + ' goto try');
- Writeln(BatchFile, 'del %0');
- Writeln(BatchFile, 'cls');
- Writeln(BatchFile, 'exit');
- 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;
- end;