Solved

Two Delphi 2 questions

Posted on 1997-05-16
2
160 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now