Windows Develop Bookmark and Share   
 index > Windows Forms General > Launching a second instance of an application
 

Launching a second instance of an application

We have an application which, by default, accesses resources using the current Windows user. Our MDI parent is called ApplicationForm.

We would like to test our application logged in as a different user. We've decided to do this by selecting the userid of the target user from a list, then clicking a button like "Launch Application" that does the following:

Thread newApplicationThread = new Thread(new ThreadStart(delegate()

{

Application.Run(new ApplicationForm("target userid"));

}));

newApplicationThread.Start();

If I never do a Join() on this thread, will I have problems? Are the message pumps separate between the two threads and their application instances?

JeffOzvold  Wednesday, March 14, 2007 9:24 PM

To launch a new instance of the application currently running, you can just use "System.Diagnostic.Process.Start()" method. You can retrieve the start information of the running process with "Process.GetCurrentProcess()".

If you want to start the new process with a different user identity, you can fill in the corresponding user name and password into "ProcessStartInfo.UserName" and "ProcessStartInfo.Password".

Here are some document links related:

Process Class

http://msdn2.microsoft.com/en-us/library/system.diagnostics.process.aspx

ProcessStartInfo Class

http://msdn2.microsoft.com/en-us/library/system.diagnostics.processstartinfo.aspx

Ting Wang  Tuesday, March 20, 2007 5:43 AM
Now that I think of it, that's pretty naive. If I do that, both threads will have the same static classes. So, I guess that's not going to work. Is there a way to launch a new instance of the application that is currently running?
JeffOzvold  Wednesday, March 14, 2007 9:39 PM
What if you split your app into two parts - a loader that lets you to pick the user, and the app itself? The loader will enable the user to pick the right account to launch the main application under, then it will spawn the main application process under that account and quit.
DmytroL  Wednesday, March 14, 2007 11:20 PM

To launch a new instance of the application currently running, you can just use "System.Diagnostic.Process.Start()" method. You can retrieve the start information of the running process with "Process.GetCurrentProcess()".

If you want to start the new process with a different user identity, you can fill in the corresponding user name and password into "ProcessStartInfo.UserName" and "ProcessStartInfo.Password".

Here are some document links related:

Process Class

http://msdn2.microsoft.com/en-us/library/system.diagnostics.process.aspx

ProcessStartInfo Class

http://msdn2.microsoft.com/en-us/library/system.diagnostics.processstartinfo.aspx

Ting Wang  Tuesday, March 20, 2007 5:43 AM
This resolved my issue. Thanks!
JeffOzvold  Friday, March 30, 2007 5:50 PM

You can use google to search for other answers

Custom Search

More Threads

• I've asked my question the wrong way
• Some labels cut off at 2/3 height on some computers
• Listwidth
• Control Arrays
• MouseMove: Cursor "slips off / drops" control
• MeasureCharacterRanges very slow when printing
• NotifyIcon icon size ?
• auto screen resolution for c# window application
• WebBrowser don't stop communication
• Private/Public components?