Switch to process
-
Hi all, I have to switch from one application to another, I have found this method: System.Diagnostics.Process.Start("application"); that allow me to open an application... Then when i press my button for the second time, i don't want to start a new application but i want to open the existing one. in this way: System.Diagnostics.Process[] myProcesses; myProcesses = System.Diagnostics.Process.GetProcessesByName("application"); i can know if my process is already running but now I don't know to show this application... Can someone help me?? Thanks a lot. Cliffer
-
Hi all, I have to switch from one application to another, I have found this method: System.Diagnostics.Process.Start("application"); that allow me to open an application... Then when i press my button for the second time, i don't want to start a new application but i want to open the existing one. in this way: System.Diagnostics.Process[] myProcesses; myProcesses = System.Diagnostics.Process.GetProcessesByName("application"); i can know if my process is already running but now I don't know to show this application... Can someone help me?? Thanks a lot. Cliffer
Hello, You could use the MainWindowHandle property of the process in combination with BringWindowtoTop method of user32.dll. [System.Runtime.InteropServices.DllImport("user32.dll")] public static extern int BringWindowToTop(IntPtr hwnd); public IntPtr HWND_TOPMOST =(IntPtr)(-1); public IntPtr HWND_NOTOPMOST =(IntPtr)(-2);
//Your method
System.Diagnostics.ProcessStartInfo psi;
psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized;
psi.FileName = "???.exe";
using(System.Diagnostics.Process process = new System.Diagnostics.Process())
{
process.Start(psi);
process.WaitForInputIdle();
BringWindowToTop(process.Handle);
}I'm using this in .Net1.1, maybe in .Net 2.0 there is a more elegant way. Hope it helps! All the best, Martin
-
Hello, You could use the MainWindowHandle property of the process in combination with BringWindowtoTop method of user32.dll. [System.Runtime.InteropServices.DllImport("user32.dll")] public static extern int BringWindowToTop(IntPtr hwnd); public IntPtr HWND_TOPMOST =(IntPtr)(-1); public IntPtr HWND_NOTOPMOST =(IntPtr)(-2);
//Your method
System.Diagnostics.ProcessStartInfo psi;
psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized;
psi.FileName = "???.exe";
using(System.Diagnostics.Process process = new System.Diagnostics.Process())
{
process.Start(psi);
process.WaitForInputIdle();
BringWindowToTop(process.Handle);
}I'm using this in .Net1.1, maybe in .Net 2.0 there is a more elegant way. Hope it helps! All the best, Martin