1

How can i run any win.exe from asp.net page?

this codes me error: The system cannot find the file specified

 System.Diagnostics.Process process1 = new System.Diagnostics.Process(); process1.StartInfo.WorkingDirectory = Request.MapPath(@"C:\"); process1.StartInfo.FileName = Request.MapPath("WindowsApplication1.exe"); process1.Start();

6 Answers 6

4

Remember that the code you posted there is running on your web server. It does not and cannot run on the user's machine. That would be a major security issue — significant enough to make the web pretty much useless.

If that's your intent, then you just need to make sure that your asp.net account — which normally runs with very restricted permissions for security reasons — has proper permissions, access, and trust to run the requested program. Otherwise you'll need to do something else.

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

Comments

2

You don't need Request.MapPath() for what you are doing, since you are already using a local path. Request.MapPath() is used to translate a app-relative URL (e.g. "~/test.htm") to a local path (e.g. "c:\inetpub\wwwroot\myapp\test.htm").

Does the application exist at c:\WindowsApplication1.exe on the server?

Comments

0

What are you trying to do ?

Is your goal here is to execute that on the clients computer, (You can't do this btw)

If it's just some .exe that you want to execute on your server when a user browses that page (I won't even begin with why this is a bad idea) then you're doing a few silly things.

Theres no need for the Request.MapPath's around your file names.

You'll also need to make sure your Webserver Identity Account has permission to access and run the file

Comments

0

Request.MapPath takes a relative URL, and returns a local filename (on the server), e.g. Request.MapPath("test.aspx") might return C:\inetpub\wwwroot\MyApp\Test.aspx.

So basically your 'web page' will be looking for an application on the server in the same directory as the web page called WindowsApplcation1.exe.

Finally - if you are expecting this windows application to run on the client this wont work, as it will run the application on the server. Automatically running files on the client would not be allowed as this would be a security risk.

Comments

0

Try this one

System.Diagnostics.Process process1 = new System.Diagnostics.Process(); process1.StartInfo.FileName = "C:\WindowsApplication1.exe";
process1.Start();

In this way application is first being downloaded and than it will run. I don't think it will run from the server.

If you want to run it from the server than better you write application in flash or silverlight/moonlight.

1 Comment

I've a bad feeling though that he thinks this will "magically" run the exe on the clients browser.
0

I am doing it so:

 var client = new Client(Int32.Parse(Session["uid"].ToString())); var genReceipt = new Process(); genReceipt.StartInfo.FileName = "Chitanta_unit.exe"; genReceipt.StartInfo.WorkingDirectory = @"C:\chitanta_unit\"; genReceipt.StartInfo.Arguments = client.ClientID.ToString(); genReceipt.Start(); genReceipt.WaitForExit(); if (genReceipt.ExitCode == 0) { Response.Redirect("~/subscriber/ch/" + client.GetChitantaFilename()); } genReceipt.Close(); 

Client class contains operations with customers. "C:\chitanta_unit\" path at the server. Server is all mine =) I ran it with clientID argument. And Chitanta_unit.exe is a ConsoleApplication

It is working well

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.