Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run cmd or exe file from asp.net page

Tags:

c#

asp.net

iis-7

I have problem with running cmd or exe file from asp.net page.

I used this code:

protected void btnRun_OnClick(object sender, EventArgs e)
{
  var p = new Process();
  var info = new ProcessStartInfo
                            {
                              FileName = Server.MapPath("~/print.cmd"),
                              UseShellExecute = false,
                              WindowStyle = ProcessWindowStyle.Hidden,
                            };
  p.StartInfo = info;
  p.Start();
  p.WaitForExit();
}

When I run my web application on VS Development Server everything is ok, but when I deploy this code on IIS (ver 7.5), the code working without errors but nothing happens.

  • I used search on google and SO, but I didn't find any solution
  • I tried http://support.microsoft.com/kb/555134 and http://support.microsoft.com/default.aspx?scid=kb;en-us;317012
  • I set 'Allow service to interact with desctop' for IIS Admin service.
  • I played with user rights but this didn't give me any results.
  • I changed Identity for Application Pools

is it possible to run cmd or exe with IIS?

like image 890
ukraine Avatar asked Dec 04 '25 15:12

ukraine


1 Answers

Try:

var info = new ProcessStartInfo
                        {
                          FileName = Server.MapPath("~/print.cmd"),
                          UseShellExecute = true,
                          Verb = "runas",
                          WindowStyle = ProcessWindowStyle.Hidden,
                        };
like image 89
Alexander Kempton Avatar answered Dec 06 '25 15:12

Alexander Kempton