class procedure TVTUpgrader.UpdateSelf(const FileName: TVTString);
var
LBatchFile: TextFile;
LBatchFileName: TVTString;
LProcessInfo: TProcessInformation;
LStartUpInfo: TStartupInfo;
begin
//批次檔名
LBatchFileName := ExtractFilePath(ParamStr(0)) + '_deleteme.bat';
//開啟檔案,設定覆蓋模式
AssignFile(LBatchFile, LBatchFileName);
Rewrite(LBatchFile);
//寫入批處理內容
Writeln(LBatchFile, ':try');
Writeln(LBatchFile, 'del "' + ParamStr(0) + '"');
Writeln(LBatchFile, 'if exist "' + ParamStr(0) + '"' + ' goto try');
Writeln(LBatchFile, 'copy "' + FileName + '" "' + ParamStr(0) + '"');
Writeln(LBatchFile, 'del "' + FileName + '"');
Writeln(LBatchFile, 'del %0');
//關閉檔案
CloseFile(LBatchFile);
//建立新進程運行批次檔
FillChar(LStartUpInfo, SizeOf(LStartUpInfo), $00);
LStartUpInfo.dwFlags := STARTF_USESHOWWINDOW;
LStartUpInfo.wShowWindow := SW_HIDE;
if CreateProcess(nil, PChar(LBatchFileName), nil, nil, False,
IDLE_PRIORITY_CLASS, nil, nil, LStartUpInfo, LProcessInfo) then
begin
CloseHandle(LProcessInfo.hThread);
CloseHandle(LProcessInfo.hProcess);
end;
end;