简体   繁体   中英

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

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

this codes me error:

 System.Diagnostics.Process process1 = new System.Diagnostics.Process();

            process1.StartInfo.WorkingDirectory = Request.MapPath(@"C:\");

            process1.StartInfo.FileName = Request.MapPath("WindowsApplication1.exe");
            process1.Start();

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.

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 (eg "~/test.htm") to a local path (eg "c:\\inetpub\\wwwroot\\myapp\\test.htm").

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

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.

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

Request.MapPath takes a relative URL, and returns a local filename (on the server), eg 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM