1

I am writing a program that searches certain web pages before closing. I would like my program to open a NEW WINDOW using the DEFAULT BROWSER. I can have my program focus the newest window instance, and then it will close that instance once it is done.

I have been staring at WebBrowser.Navigate and System.Diagnostics.Process.Start(target) all day but I cant find the sweet spot with either of them.

WebBrowser.Navigate always opens IE, I have been looking in the API and can't find a way to change the program used. Does anyone else see something that I dont? Is there a way to change the application used?

System.Diagnostics.Process.Start(target) opens in a new tab, not a new window like navigate does. However none of the overloaded functions from the API have a way of saying "create a new instance or window".

this is my issue, they both have pieces that I want, but I cant figure out how to get the pieces I need for either one.

I would be extremely grateful for you help. I have been looking for hours now and I can seem to come to a solution.

code sample for Jester:

            Process defaultbrowser = new Process();


            defaultbrowser.StartInfo.CreateNoWindow = true;
            defaultbrowser = Process.Start(target);       

            int waitTime = Convert.ToInt32(numericUpDown2.Value);
           System.Threading.Thread.Sleep(waitTime*1000);

           defaultbrowser.CloseMainWindow();
           defaultbrowser.Close();

furthermore my Close() function is causing a runtime error that says;

System.NullReferenceException: Object reference not set to an instance of an object.

which seems silly because too me the above code makes me think that my defaultbrowser is an instance of a process, which is then supposed to be able to call the non-static function "close()".

3 Answers 3

2

ok If I got your problem right you are looking for a way to open a web page in the "default" browser.

That can be done by simply make a new process like:

Process.Start("http://google.com");

If you would like to control witch browser gets used you can do it by passing the web address to the browser's exe file as a parameter:

System.Diagnostics.Process.Start("PATH to exe", "Command Line Arguments");

To start the process in the new window pass a ProcessInfo object to the Process.Start And set the CreateNoWindow more info on that

Sign up to request clarification or add additional context in comments.

1 Comment

ok, I think you hit the nail on the head with CreateNoWindow. I was unaware of that property. However when I use it exactly as the API does, it doesnt open in a new window for some reason. Any ideas? I will post the relevant code in my question above for you to see. Perhaps I have an error.
0

Hey To check if it's loaded wherever, do:

if(browser.ReadyState == WebBrowserReadyState.Complete) {
// It's Open!
}

2 Comments

awesome, that is a huge help! the Microsoft support pages are so huge I have trouble finding what I need. Thank you
Thanks for comment,If post is really helpful for you please mark as answer.
0

You should use System.Diagnostics.Process like that:

Process Chrome = new Process(); //Create the process
Chrome.StartInfo.FileName = @"C:\Program Files\Google\Chrome\Application\chrome.exe";  // Needs to be full path
Chrome.StartInfo.Arguments = ""; // If you have any arguments
Chrome.Start();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.