1

I have an executable built in Visual Studio which normally runs (i.e. in our production environment) as a single-instance application. I accomplished this by using the "Make single instance application" check box in the "Windows application framework properties" area on the "Application" tab of the project's properties, as shown here:

enter image description here

My application is a workflow application, so it involves passing workflow items from one user to another; all involved users have this application running on their own computers.

In my development environment, however, it's often the case that I want to impersonate a few different users at the same time (this ability to impersonate users is a feature that the users themselves are not aware of) in order to troubleshoot a complex bug in the application. It's easier to have multiple instances open simultaneously, each impersonating a different user, and in some cases, it's necessary because the bug might be something that only occurs once the initial overhead of starting the application has been undertaken -- in other words, closing the application to switch user contexts releases state which will preclude the bug.

I'm able to accomplish this easily enough by un-checking the above-mentioned check box; however, I then have to remember to re-check it at some point before I deploy the bug fix. It would be better if I could set something external to the application that lives only on my development computer, e.g. a registry value, which triggers the application to behave as a multiple-instance application. I have searched high and low, and it appears that no one has asked this question before.

Has anyone here ever encountered this? Your help would be much appreciated.

rory.ap
  • 34,009
  • 10
  • 83
  • 174
  • 3
    Look at this answer: http://stackoverflow.com/a/522874/573218 – John Koerner Oct 04 '13 at 16:46
  • Are you positive that if you use RunAs that you can't run multiple instances at the same time? Just cursious. Because RunAs runs under different profile. I have an application that is set to a single instance deployed on a terminal server without issue. – jcwrequests Oct 04 '13 at 23:50
  • @jcwrequests -- Hmmm...that's a good thought. I'll check that out. Thanks. – rory.ap Oct 07 '13 at 14:34

1 Answers1

1

I'm not sure that this is the most elegant way to do what you require but it's something we use. We often need to test multiple instances of an app (where the users are not allowed to run multiple instances.)

When the VS compiler runs code, it runs it with a .vshost in the instance, so you won't get the problem when running your app while debugging at the same time with this method. Also, if you would like to run multiple instances in Windows, just rename the .EXE and run.

Dim myProcesses() As Process
myProcesses = process.GetProcessesByName("NameOfYourApp")
If myProcesses.Length > 1 Then
    'Close app here 
    '(You can just .Close the startup form)
End If
Daniel Gee
  • 426
  • 7
  • 21