Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Process.Start("IEXPLORE.EXE") immediately fires the Exited event after launch.. why?

i have a strange problem with IE8 installed in xp. i was trying to launch IE using an System.Diagnostics.Process.Start method in c#. And i have a requirement to trap the exited event of the IE and do some operation. But i ended up in a rather strange problem where the IE immediately fires the exited event after launch.

this is the sample code

     Process objProcess = Process.Start("IEXPLORE.EXE", "http://google.com");

     if (objProcess != null)
    {
        objProcess.EnableRaisingEvents = true;
        objProcess.Exited += new EventHandler(myProcess_Exited);        
    }

    public  static void myProcess_Exited(object sender, System.EventArgs e)
    {
        MessageBox.Show("You exited");
    }

But the above code perfectly works when laucnching different process (ex:notepad) and it fires the exit event when i close the exe.

this only gives problem launching IE 8. Can someone clarify me what is the problem??

UPDATE

Most friends replied my post and saying why you can't just use an URL? why stick with IE?

here the reason

the ultimate aim of the app is to launch an URL from the windows application and will hide an exe when working on the IE. And show the exe after closing the IE.

Thanks

like image 277
RameshVel Avatar asked Dec 01 '09 09:12

RameshVel


People also ask

How does process start work?

Start(String, String) Starts a process resource by specifying the name of an application and a set of command-line arguments, and associates the resource with a new Process component.

What is process start in C#?

C# Process class provides Start method for launching an exe from code. The Process class is in the System. Diagnostics namespace that has methods to run a .exe file to see any document or a webpage. The Process class provides Start methods for launching another application in the C# Programming.

How do I start a process in VB net?

Start another application using your . NET code As a . NET method, Start has a series of overloads, which are different sets of parameters that determine exactly what the method does. The overloads let you specify just about any set of parameters that you might want to pass to another process when it starts.


1 Answers

Most probably is that you have IE already running as a process, so when you try to launch it again as a new process it looks that there are IE running already, tells it that user initiated a new window (so the initial IE will create a "new" window rather than a new one) and exit.

Possible solution: try starting the process with "-nomerge" command line option:

    Process objProcess = Process.Start("IEXPLORE.EXE", "-nomerge http://google.com/");

Interesting observation: objProcess.ExitCode (for IE8 at least) will be equal to 0 if exited passing control to another instance, and 1 if it was actually closed by user.

like image 116
Regent Avatar answered Oct 01 '22 10:10

Regent



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!