Solved

Multiple App Instance Blocking With Windows User Profiles

Posted on 2007-12-04
4
150 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

Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

Question has a verified solution.

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

Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
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 …
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

726 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