Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to make a program only run once per Windows session Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
08-Dec-02
Category
System
Language
Delphi 2.x
Views
107
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius 

How can I prevent the user from running my program twice during the same Windows 
session? I want to force the user to log into Windows again before my application 
can be started a second time.

Answer:

A way to make a program only be able to run once in every session is to create a 
unique global atom string on first run. Then on the following run, check if the 
string exists, and not run the program if the string atom is present. For example:
1   
2   procedure TForm1.FormShow(Sender: TObject);
3   var
4     atom: Integer;
5   begin
6     if (GlobalFindAtom('This_is_some_unique_text') = 0) then
7       atom := GlobalAddAtom('This_is_some_unique_text')
8     else
9     begin
10      ShowMessage('This application can only be run once for every Windows Session.');
11      Close;
12    end;
13  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC