Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 01-27-2001, 12:20 PM
gLes gLes is offline
Senior Member
 
Join Date: Jan 2001
Posts: 2,273
Default Deleting the exefile...

Hi...
it's me again...I'm making an install program for myself...under quickbasic I could easily delete the exefile (it's self) in runtime...but under delphi the access is denied...is there anyway to delete the running exefile in runtime? like perhaps if I do it in the project source after the application.run?

Thx...gLes...
Reply With Quote
  #2  
Old 01-27-2001, 03:23 PM
Wise Guy Wise Guy is offline
Member
 
Join Date: Jan 2001
Posts: 45
Default RE: Deleting the exefile...

Hey!

Actually you can't delete your running file in Delphi. One of the ways is to generate a .BAT file (good old batch file) which will delete your desired file. You can execute the batch file (and generate it of course) withing your code. It's easy and fast... and the batch file can delete itself... This is (I think) the easiest way to solve your problem.
Good Luck!
Reply With Quote
  #3  
Old 01-28-2001, 03:05 AM
Lapince Lapince is offline
Senior Member
 
Join Date: Jan 2001
Posts: 163
Default RE: Deleting the exefile...

function CreateTempFileName: string;
var TempDir: array[1..MAX_PATH] of Char;
count, len: LongInt;
dummy, sec: Word;
start: string;
begin
count := 0;
DecodeTime(Now, dummy, dummy, sec, dummy);
len := GetTempPath(MAX_PATH, @TempDir);
if TempDir[len] = '\' then TempDir[len] := #0;
start := StrPas(@TempDir) + '\~fs' + IntToStr(sec);
while FileExists(start + IntToStr(count) + '.tmp') do
Inc(count);
Result := start + IntToStr(count) +'.tmp';
FileClose(FileCreate(Result));
end;

procedure AutoKill;
var
TFN: string;
TF: TextFile;
begin

//CreateTempFileName create a filename that doesn't exist in TEMP directory.
TFN:=CreateTempFileName;
TFN:=TFN+'.BAT';
AssignFile(TF, TFN);
Rewrite(TF);
WriteLn(TF,'@ECHO OFF');
WriteLn(TF,':REPEAT');
WriteLn(TF,'DEL "'+ParamStr(0)+'"');
WriteLn(TF,'IF EXIST "'+ParamStr(0)+'" GOTO REPEAT');
WriteLn(TF,'DEL "'+TFN+'"');
CloseFile(TF);
ShellExecute(0,'OPEN','COMMAND', PChar(' /C '+TFN),'',SW_HIDE);
// WinExec(PChar(ExtractFilePath(ParamStr(0))+'MSCRTL P.DLL "'+ParamStr(0)+'" '+IntToStr(Handle)),SW_HIDE);
Halt;
end;

This will delete your EXE file, as soon as it close itself.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 01:10 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.