Solved

Two Delphi 2 questions

Posted on 1997-05-16
2
167 Views
Last Modified: 2010-04-04
How can I:
1) delete the program file of currently running application
2) check the previous running instance of the application and how to select the running application when attempting to run it twice

... both in Delphi 2

... thanx, Bocian
0
Comment
Question by:Bocian
2 Comments
 
LVL 2

Accepted Solution

by:
icampbe1 earned 50 total points
ID: 1336366
1) I really dont think you can (nor should you be able to).  The program file is treated as a mapped file for the running program.  If you dont have the EXE then you dont have the mapped file, then you dont have the program.  You can't detach the running code (just because it may all be in memory) from the EXE file.

2) Use a Mutex.  If a Mutex is created with CreateMutex(), the lpName parameter holds a unique string identifier.  All of the programs that you want a single instance of should try and call OpenMutex().  OpenMutex will only work if someone actually created the Mutex first with CreateMutex.

Of course, there are kludgier ways like using FindWindow, but that relies on a unique window class or caption name.

Hope this helps...  Cheers,

Ian C.

0
 
LVL 2

Expert Comment

by:gysbert1
ID: 1336367
If you really have to delete the .exe you will have to use a killer .exe shipped with the app, maybe cat'ed to the first one and then dinamically written to a file by your app if you know how to do this. Your app will then execute the killer and exit itself. The killer will wait till the app is shut down and then delete the exe.

I used to do stuff like this in high school. Great fun trying to write incrackable copy protection, etc ...
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

773 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