Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

One instance and Kill program

Posted on 2003-11-10
2
Medium Priority
?
435 Views
Last Modified: 2010-04-05
1) How can i make the program only run one (one instance) at a time ?
2) How can i kill the program if the program can not close normally ?
I had try the release(). Although the form was closed, i still
can see there is the process in Process Manager.
0
Comment
Question by:expert173173
[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 4

Accepted Solution

by:
BedouinDN earned 300 total points
ID: 9719616
For single instance you can use a mutex.
Place the following in the source of your project (DPR) before the Application.Initialize part :-)
//---------------------------------
var
MutexHandle: THandle;

begin
MutexHandle := CreateMutex(nil, TRUE, App Name Here);
        if MutexHandle <> 0 then
        begin
                if GetLastError = ERROR_ALREADY_EXISTS then
                begin
                CloseHandle(MutexHandle);
                Halt; // 'Halt' Is the actual one that prevents a second
                end;
        end;
//-------------------------------------------------------------------------------

As for closing the application - When you close the form named as the main form, the application should terminate.
Failing this, you can try calling the Application.Terminate method instead of calling close however this is a bit nasty.
0
 
LVL 2

Expert Comment

by:SaLz
ID: 9719884
if your wondering what you should put in the app name it is the Class as in what you have named your form
you could put PChar((form1)) if you get errors
MutexHandle := CreateMutex(nil, TRUE, PChar(form1));
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
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…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

618 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