473,769 Members | 2,120 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem using System.Diagnost ics.Process to launch Internet Explorer

I have been trying for some time now to launch Internet Explorer from
my code. I have read the MSDN notes on this way of starting processes
and used their example but couldn't get it to work.
I then searched the forums and made ammendments suggested to previous
posters but it still isn't working. Here is my StartInternetEx plorer()
method. Could you please look and see what I am doing wrong?

Thankyou.

Gary.

private void StartInternetEx plorer()
{
Process myProcess = new Process();

try
{

myProcess.Start Info.FileName = "c:\\Progra m
Files\\iexplore .exe";
myProcess.Start Info.Arguments =
"http://www.google.co.u k";
myProcess.Enabl eRaisingEvents = false;
myProcess.Start ();
myProcess.WaitF orExit();
}
catch (Win32Exception e)
{
if(e.NativeErro rCode == ERROR_FILE_NOT_ FOUND)
{
Console.WriteLi ne(e.Message + ". Internet Explorer
not in default location.");
}

else if (e.NativeErrorC ode == ERROR_ACCESS_DE NIED)
{
// Note that if your word processor might generate
exceptions
// such as this, which are handled first.
Console.WriteLi ne(e.Message + ". You do not have
permission to run this file.");
}
}
}

Dec 1 '06 #1
5 7850
Shouldn't FileName be "c:\\Progra m Files\\Internet
Explorer\\iexpl ore.exe" ?

On Dec 1, 10:19 am, garyuse...@mywa y.com wrote:
I have been trying for some time now to launch Internet Explorer from
my code. I have read the MSDN notes on this way of starting processes
and used their example but couldn't get it to work.
I then searched the forums and made ammendments suggested to previous
posters but it still isn't working. Here is my StartInternetEx plorer()
method. Could you please look and see what I am doing wrong?

Thankyou.

Gary.

private void StartInternetEx plorer()
{
Process myProcess = new Process();

try
{

myProcess.Start Info.FileName = "c:\\Progra m
Files\\iexplore .exe";
myProcess.Start Info.Arguments =
"http://www.google.co.u k";
myProcess.Enabl eRaisingEvents = false;
myProcess.Start ();
myProcess.WaitF orExit();
}
catch (Win32Exception e)
{
if(e.NativeErro rCode == ERROR_FILE_NOT_ FOUND)
{
Console.WriteLi ne(e.Message + ". Internet Explorer
not in default location.");
}

else if (e.NativeErrorC ode == ERROR_ACCESS_DE NIED)
{
// Note that if your word processor might generate
exceptions
// such as this, which are handled first.
Console.WriteLi ne(e.Message + ". You do not have
permission to run this file.");
}
}
}
Dec 1 '06 #2
First - iexplore.exe doesn't live in program files, and 2nd, even if it
did you shouldn't assume C:\Program Files - you would check the
environment variables.

A better option is to let the path worry about this - just use
"iexplore.e xe" as the command.

An *even* better option is to let the user's prefs decide which browser
to launch - use "http://someurl" as the command, and forget about the
args.

Marc

Dec 1 '06 #3
That did it. I didn't even think of the path being wrong as I thought
my try catch block would have taken care of filenames being faulty.

Can you please tell me why that wasn't the case?

Dec 1 '06 #4
Also - this is a small part of an app i'm writing which directly
interfaces with internet explorer, so it's only for internet explorer.
That's why i hard coded iexplore.exe.

I'll take a look at the paths though and try to make it more general
thanks!

Dec 1 '06 #5
Fixed. I was using console.writeli ne in a windows app...
Thanks for your help everyone.
Gary.

Peter wrote:
Try this:

System.Diagnost ics.Process.Sta rt("http://www.google.co.u k");

the http protocol moniker in the Registry will take care of the rest.

Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"ga********@myw ay.com" wrote:
I have been trying for some time now to launch Internet Explorer from
my code. I have read the MSDN notes on this way of starting processes
and used their example but couldn't get it to work.
I then searched the forums and made ammendments suggested to previous
posters but it still isn't working. Here is my StartInternetEx plorer()
method. Could you please look and see what I am doing wrong?

Thankyou.

Gary.

private void StartInternetEx plorer()
{
Process myProcess = new Process();

try
{

myProcess.Start Info.FileName = "c:\\Progra m
Files\\iexplore .exe";
myProcess.Start Info.Arguments =
"http://www.google.co.u k";
myProcess.Enabl eRaisingEvents = false;
myProcess.Start ();
myProcess.WaitF orExit();
}
catch (Win32Exception e)
{
if(e.NativeErro rCode == ERROR_FILE_NOT_ FOUND)
{
Console.WriteLi ne(e.Message + ". Internet Explorer
not in default location.");
}

else if (e.NativeErrorC ode == ERROR_ACCESS_DE NIED)
{
// Note that if your word processor might generate
exceptions
// such as this, which are handled first.
Console.WriteLi ne(e.Message + ". You do not have
permission to run this file.");
}
}
}
Dec 1 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
8375
by: grutta | last post by:
I am writing a windows service that will recieve notification when a USB Device is insterted into the machine. I have used the RegisterDeviceNotification and the RegisterServiceCtrlHandlerEx with a handler. The handler portion seems to fail indicating that my parameters are invalid. I am getting an error code 126 when i try to register the handler and 28 when i register for event notification. Any ideas as to what the deal is? I am...
2
5680
by: Charlie Kunkel | last post by:
I need help. I have a directory I'm watching for creation of .TIF files, whereupon creation, I need to launch a process (command line exe) that converts the TIF file to a postscript file. (using tif2ps.exe) The problem is, I can't open the .TIF file as long as my application's running! tif2ps.exe always tells me "Cannot open file". Here's the code in my Windows C# App: private void button1_Click(object sender, System.EventArgs e) {
4
14207
by: Yiu | last post by:
upgent help i want to start IE explorer using C# i try many code such as below: ProcessStartInfo startInfo = new ProcessStartInfo("IEXPLORE.EXE"); Process.Start(startInfo); or Process process = new Process(); process.StartInfo.FileName = "C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE";
5
7431
by: hellrazor | last post by:
HI there, I am developing a client side app which requires me to launch another program when a user clicks a button on a web page. I thought I'd create an asp.net page (using c# ) to accomplish this. After much research I found that it's not that simple. The asp process runs under an aspnet user, which does not let me launch my program. I ran accross some code that is supposed to impersonate the logged in user, but I get the following...
2
6530
by: Robin Tucker | last post by:
I'm having problems with System.Diag here. When I double click the item (on my desktop), it launches in Windows Fax and Picture Viewer, but when I try to launch it from my VB program, I get the following exception: "A first chance exception of type 'System.ComponentModel.Win32Exception' occurred in system.dll Additional information: No application is associated with the specified file for this operation"
4
1475
by: Blaxer | last post by:
I am using the following code to open an instance of Internet Explorer with a specific URL. Dim Argument_String as String = "www.yahoo.com" System.Diagnostics.Process.Start("C:\Program Files\Internet Explorer\iexplore.exe", Argument_String) If I have the new XP SP2 IE pop-up blocker enabled the browser does not come up at all, if I disable it it "pops-up" just fine. If I put, for example, www.yahoo.com in the list of sites to not...
13
39899
by: Chris Johnson | last post by:
I have what seems to be such a simple thing yet I cannot figure out how to do it. I am using a streamwriter to build a text file. At the end of the process I want to open that same text file in notepad so the user can see what was built. I cannot for the life of me figure out how to get the text file to open up in notepad on the screen. All the processes I have tried opens the file into the filestream again.
0
849
by: Daniel | last post by:
C# windows service freezes on System.Diagnostics.Process.Start(info) When I launch PSCP from a C# windows service and launch pscp 0.53 there are no issues. but when I use C# windows service to launch pscp 0.58 C# freezes in System.Diagnostics.Process.Start(info)? pscp 0.58 works fine at command line, but causes C# to freeze on ystem.Diagnostics.Process.Start(info) also i noticed that the pscp process does not show in taske manager while...
2
6101
by: JDeats | last post by:
When a user double clicks on file item in Windows Explorer, Windows tries to open the document with whatever application is related to it's file extension. In my WinForms application I would like to be able to shell out and launch referenced applications in this way (to simplify what I'm trying to accomplish, let's say I'm trying to create a Windows Explorer like application using WinForms and C# for .NET 2.0 What's the best way to go...
0
9579
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9422
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9857
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8867
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7404
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5444
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3952
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2812
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.