tags:

views:

511

answers:

6

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();
+3  A: 
Joel Coehoorn
A: 

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.

Sharique
I've a bad feeling though that he thinks this will "magically" run the exe on the clients browser.
Eoin Campbell
I have similar feeling.
Sharique
A: 

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

Eoin Campbell
+2  A: 

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?

M4N
A: 

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.

samjudson
A: 

I 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

Its work well