Registriert seit: 24. Sep 2003
59 Beiträge
|
Re: Sich selbst neu starten?
25. Sep 2006, 00:23
Eine weitere Möglichkeit wäre diese:
Delphi-Quellcode:
procedure RestartApplication;
function GetTmpDir: String;
var
PC: PChar;
begin
PC := StrAlloc(MAX_PATH + 1);
GetTempPath(MAX_PATH, PC);
Result := String(PC);
StrDispose(PC);
end;
function GetTmpFileName(Ext: String): String;
var
PC: PChar;
begin
PC := StrAlloc(MAX_PATH + 1);
GetTempFileName(PChar(GetTmpDir), 'uis', 0, PC);
Result := string(PC);
Result := ChangeFileExt(Result, Ext);
StrDispose(PC);
end;
var
BatchFile: TStringList;
BatchName: String;
begin
batchname := GetTmpFileName('.bat');
FileSetAttr(ParamStr(0), 0);
BatchFile := TStringList.Create;
with BatchFile do
begin
try
Add(':Label1');
Add(Copy(ParamStr(0), 0, 2));
Add('cd ' + Copy(ExtractFilePath(ParamStr(0)), 4, Length(ExtractFilePath(ParamStr(0))) -1));
Add('start ' + ExtractFileName(ParamStr(0)));
Add('del ' + BatchName);
SaveToFile(BatchName);
ChDir(GetTmpDir);
WinExec(PChar(BatchName), SW_HIDE);
finally
BatchFile.Free;
end;
Halt;
end;
Application.Terminate;
end;
|
|
Zitat
|