简体   繁体   中英

Running Process on Server via ASP.NET/C# on IIS

What I am trying to do is run a batch file that is located on the webserver's desktop when a button is clicked. This is what I have thus far.

ProcessStartInfo psi = new ProcessStartInfo("Notepad.exe");
   psi.WorkingDirectory = @"C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Accessories";
   psi.UseShellExecute = false;
   psi.UserName = "administrator";  //username
   psi.Password = secure;  //secure string
var process = Process.Start(psi);

When I debug it, it does exactly what I want it to, but when I access the site on IIS (localhost:81) the batch file never runs. I've tried many different variants of ProcessStartInfo and Process with no luck. I've tested the username and password and they are both correct too.

I don't get any errors, the button just triggers a page post back.

I have given IUSR and IIS_IUSRS permissions to the file, and still nothing runs. I also removed the username and password and set the UseShellExecute to true, but that did nothing as well.

EDIT:

It looks like everyone thinks its some permissions. Any idea on what I need to do to allow IIS to open the process?

Thanks in advance!

Just change the third line to this:

  psi.UseShellExecute = true;

or read this article which really gets the work done:

http://support.microsoft.com/default.aspx?scid=kb;EN-US;889251

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