views:

673

answers:

1

Hi,

I am using the following code to fire the iexplore process. This is done in a simple console app.

public static void StartIExplorer()
        {
            ProcessStartInfo info = new ProcessStartInfo("iexplore");
            info.UseShellExecute = false;
            info.RedirectStandardInput = true;
            info.RedirectStandardOutput = true;
            info.RedirectStandardError = true;

            string password = "password";
            SecureString securePassword = new SecureString();

            for (int i = 0; i < password.Length; i++)
                securePassword.AppendChar(Convert.ToChar(password[i]));

            info.UserName = "userName";
            info.Password = securePassword;
            info.Domain = "domain";

            try
            {
                Process.Start(info);
            }
            catch (System.ComponentModel.Win32Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

        }

The above code is throwing the error {"The system cannot find the file specified"}. The same code when run without specifying the user credentials works fine. I am not sure why it is throwing this error.

Can someone please explain?

Thanks.

+5  A: 

Try to replace your initialization code with:

ProcessStartInfo info = new ProcessStartInfo(@"C:\Program Files\Internet Explorer\iexplore.exe");

Using non full filepath on Process.Start only works if the file is found in System32 folder.

Jojo Sardez
This worked. Thanks :)
Rashmi Pandit
We should specify the full file name as the UseShellExecute is set to false.
Rashmi Pandit
@Rashmi Pandit - yes we should. I already encountered the same problem before :). Don't forget to accept and upvote the answer :)
Jojo Sardez
Of course, you should *really* replace it with the *actual* path to the program on the user's system. There isn't always a C: drive, and the program folder isn't always spelled "Program Files."
Rob Kennedy
Thanks, this solved my issue.
David_Jarrett