Solved

Multiple App Instance Blocking With Windows User Profiles

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
If you get continual lockouts after changing your Active Directory password, there are several possible reasons.  Two of the most common are using other devices to access your email and stored passwords in the credential manager of windows.
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

867 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now