Solved

Two Delphi 2 questions

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

732 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