Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Deleting a file from within itself

Posted on 1999-10-14
9
Medium Priority
?
127 Views
Last Modified: 2010-07-27
I want to automatically delete an exe file after the user clicks - the close button. This application should only be used once. The close button is tied to the same application I want to delete. Can this be done?
0
Comment
Question by:routerboy309
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 6

Expert Comment

by:edey
ID: 2127705
instead of calling the exe directly you could write a batch file that deletes the exe

GL
Mike
0
 

Accepted Solution

by:
edwinvanrijkom earned 100 total points
ID: 2127817
There's a freeware component that does just what you want at http://www.krasimir.com/Components.htm

Greetz, Edwin.
0
 
LVL 17

Expert Comment

by:inthe
ID: 2131531
listening..
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Expert Comment

by:Indefrei
ID: 2132764
>> a batch file that deletes the exe
and the batchfile itself
0
 
LVL 17

Expert Comment

by:inthe
ID: 2132969
are you using the compoenent of edwinvanrijkom or use this example of batch file:
 

       procedure form1.onclosequery
        Command         : string;
        TSI             : Tstartupinfo;
        TPI             : Tprocessinformation;
           begin
           memo1.text := '@Echo Off' +#13+#10 +'del' +application.exename +#13+#10
       +'del c:\killer.bat';
           memo1.text.savetofile('c:\killer.bat')
       {do whatever you need to do before you'll close the app}
           command := 'c:\killer.bat';
           createprocess(nil, pchar(command + ' ' + ' '), nil, nil, false,
       normal_priority_class, nil, workdir, tsi, tpi);
       application.terminate;
       end;

Regards Barry
0
 

Author Comment

by:routerboy309
ID: 2135621
Seems to me the best and easiest way is to call the Bat from a ShellExecute method...and this appears to work (with lots of pauses). And then yes.... I can get the bat file itself to be reoved. My only problem now is that the bat file is so fast, the exe is still 'active' and on NT, I can't get the exe to be deleted until the process is done. So how do I add a minor 'wait' in the bat file and then execute the delete (del) statement?
0
 
LVL 17

Expert Comment

by:inthe
ID: 2136556
no
i dunno what your program is doing codewise but its better to have the bat file assigned to "on close" event then it works ok ;-) then just try calling form1.close; etc instead of shellexectute..

0
 

Author Comment

by:routerboy309
ID: 2136731
Using the example provided above about adding a createProcess, I have added this:

workdir := 'C:\Program Files\Common Files\Myfiles';
command := 'C:\Program Files\Common Files\MyFiles\Assist.bat';
CreateProcess(nil, pchar(command + ' ' + ' '), nil, nil, false, normal_priority_class, nil,
              pchar(workdir), tsi, tpi);

But when I close the application, I get an error that the Kernel.dll failed to Initialize. What does this mean?
0
 
LVL 17

Expert Comment

by:inthe
ID: 2142895
Hi,
dunno why that eror comes up:
try this ive tested and seems to work ok:
where the exe and the bat are in the myfiles directory
i changed a bit cause the "del" function messes up when passing it too many directorys on the command line.

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
 var
  Command : string;
  TSI     : Tstartupinfo;
  TPI     : Tprocessinformation;
 begin
memo1.text := '@Echo Off' +#13+#10 +'del ' +extractfilename(paramStr(0))+#13+#10+'del Assist.bat';
memo1.Lines.SaveToFile('C:\Program Files\Common Files\MyFiles\Assist.bat');
command := 'Assist.bat';
winexec(pchar(command),SW_HIDE);
application.terminate;
end;
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question