Error trying to open web page using System.Diagnostics.Process.Start

  • Thread starter Thread starter wadefleming
  • Start date Start date
W

wadefleming

I have the follwong code:

private void ButtonOpen_Click(object sender, System.EventArgs e)
{
System.Diagnostics.Process.Start("http://www.google.com");
}

which results in the following exception:
'An attempt was made to reference a token that does not exist '

What am I doing wrong? I'm not sure of the exact meaning of this error.
Thanks
Wade
 
Following up on this if I try

System.Diagnostics.Process.Start("notepad.exe");

I get no error, but notepad does not start either. I have also tried
using the full path name.
 
Following up on this if I try

System.Diagnostics.Process.Start("notepad.exe");

I get no error, but notepad does not start either. I have also tried
using the full path name.
 
Wade,

This can much shorter however to show you a full version.
\\\
System.Diagnostics.Process p =
new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo pi =
new System.Diagnostics.ProcessStartInfo();
pi.FileName = "http://www.google.com";
p.StartInfo = pi;
p.Start();
///
I hope this helps?

Cor
 
Thanks for the reply, but I am still getting similar results. That is,
when trying to execute "notepad.exe" I get no exception, in fact
p.Start() returns true, however notepad does not start.

When setting the filename to "http://www.google.com", I get the same
error as before, 'An attempt was made to reference a token that does
not exist ', on the line p.Start()

Any ideas?
 
Wade,

I tested this one and did work completly

\\\
System.Diagnostics.Process p =
new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo pi =
new System.Diagnostics.ProcessStartInfo();
pi.Arguments = "c:\\windows\\win.ini";
pi.FileName = "notepad.exe";
p.StartInfo = pi;
p.Start();

Are you starting this maybe from a Service or from a Webpage (what will not
work)

I hope this helps however?

Cor
 
Thanks, but still did not work, same behaviour as before. However I am
trying to start it from an .aspx page (is this what you mean by
webpage?) If that isn't going to work, can you suggest an alternative
method?
 
Wade,
Thanks, but still did not work, same behaviour as before. However I am
trying to start it from an .aspx page (is this what you mean by
webpage?) If that isn't going to work, can you suggest an alternative
method?

When you start this, it should start on your "webserver" when you have given
your ASPNET user rights for accessing IE exe on your WebServer and I
strongly advice you not to do that.

I don't believe that this is the process you are after.

I think that this is better for what you probably want.

Not tested roughly changed from VBNet.
\\\
string str;
str = "@<script language=javascript> {window.open('http://www.google.com');}
</script>";
RegisterStartupScript("Startup", str);
///

Cor
 
HI Wade, I ran into a similar problem and I found the answer at MS - of
all places. I added the
<identity inpersonate="true" /> tag to the web.config file. Fixed that
problem, but I ran into another. Oh well!

Rick.
 
I have a similar problem, asp.net page. I need to open a web page from
the server side. I am not very familar with JAVA. The Code
I am assumming I would need to build and register then execute the java
script. Not sure I know how to do this. Any help would be appreciated.
 
Olivier,

I think it is better not to connect questions to questions, they look like
answers, make your own questions and put it in the newsgroup.

Now it is maybe simular in your opinion, however that can only be partially.

It sounds for me that you want to use a
Response.Redirect(pageUrl) and in that the code as showed by me in this
thread, however I am not sure of that.

I hope this helps you starting to find your answer

Cor
 
Back
Top