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
Solved

Multiple App Instance Blocking With Windows User Profiles

Posted on 2007-12-04
4
149 Views
Last Modified: 2010-04-21
I've already seen the solution for blocking multiple app instances under a single Windows profile (i.e. AlreadyRunning := hPrevInst <> 0), but I noticed that doesn't work when the first instance is running under one profile and the second instance is running under another. Can this be done?
0
Comment
Question by:BradKilmer
  • 2
  • 2
4 Comments
 
LVL 28

Expert Comment

by:2266180
ID: 20409727
it's pretty hard telling what kind of method you are using.
is that hPrefInst  a mutex handle?
if not, then that's your problem.

the following is stripped from one of my projects.
resourcestring
  OnlyOneInstace = 'Only one instance of your-app-name is allowed to run.';
 
var mutex:THandle;
    m_single_id:string='your-app-name-1DBC2182-F7C6-423A-AB04-530B60772263';// this GUID can be changed of course. just hit ctrl+shift+g and delete the brackets
 
initialization
 
  Mutex := CreateMutex(nil, True, pansichar(m_single_id));
  if (Mutex = 0) or (GetLastError <> 0) then
  begin
    showmessage(OnlyOneInstace);
    halt(1);
  end;

Open in new window

0
 

Author Comment

by:BradKilmer
ID: 20413569
I made a small app using the snippet above and ran it under my usual profile. When I tried to launch a second copy, the snippet worked (the message was shown and the app halted). However, when I switched users (leaving the app running under the first profile), I was able to launch a second copy under the second user profile. I need to block this in my target app: my target app is an alarm dialer that interfaces with a SCADA server and uses a voice modem to contact people in the event of an alarm. The alarm dialer is configured using projects and when the second copy of the selected project is launched, it tries to acquire control of the COM port to which the modem is attached (which is the same port already being used by the first instance).

We have an Australian customer that has his system configured in such a way that whenever a user signs in to a remote session, the SCADA software treis to spawn a new copy of our dialer. The real solution to the larger problem would be to sparate the alarm dialer into two apps (with the internal control logic running as a service app and a viewer client running as a normal task bar app without limit to the number of instances). This will require a major rewrite of a 220,000 line app, so I'm just trying to enforce the single instance across profiles as a temporary fix.

I'm currently trying to work around the profile issue by periodically poking the TApplication.Handle plus a time-stamp into a global registry key for the duration of the app run, if and when a second copy tries to launch, the second copy will see that the registry key has recently been poked, attempt to verify whether or not the app with the specified handle is still active, and if so, halt. I'll post my results if they work.

Thanks for the suggestion
BK
0
 
LVL 28

Accepted Solution

by:
2266180 earned 125 total points
ID: 20413712
I looked at
http://msdn2.microsoft.com/en-us/library/ms682411.aspx
and they mention to prefix the mutex name with "Global\". try that since you already have the test applicaiton made ;)

also note the note for win2000, as it will be ignored if terminal services is not running.
0
 

Author Closing Comment

by:BradKilmer
ID: 31412757
That did the trick! Thanks!
0

Featured Post

Easy, flexible multimedia distribution & control

Coming soon!  Ideal for large-scale A/V applications, ATEN's VM3200 Modular Matrix Switch is an all-in-one solution that simplifies video wall integration. Easily customize display layouts to see what you want, how you want it in 4k.

Question has a verified solution.

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

Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
In this article, I will show you HOW TO: Perform a Physical to Virtual (P2V) Conversion the easy way from a computer backup (image).
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

809 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