简体   繁体   English

通过IIS上的ASP.NET/C#在服务器上运行进程

[英]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. 我想做的是,单击按钮时运行一个位于Web服务器桌面上的批处理文件。 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. 当我调试它时,它确实可以实现我想要的功能,但是当我在IIS(localhost:81)上访问该站点时,该批处理文件将永远不会运行。 I've tried many different variants of ProcessStartInfo and Process with no luck. 我已经尝试了ProcessStartInfo和Process的许多不同变体,但都没有碰到运气。 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. 我已授予IUSR和IIS_IUSRS对该文件的权限,但仍然无法运行。 I also removed the username and password and set the UseShellExecute to true, but that did nothing as well. 我还删除了用户名和密码,并将UseShellExecute设置为true,但这也无济于事。

EDIT: 编辑:

It looks like everyone thinks its some permissions. 似乎每个人都认为它具有一定的权限。 Any idea on what I need to do to allow IIS to open the process? 关于允许IIS打开进程需要做什么的任何想法?

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 http://support.microsoft.com/default.aspx?scid=kb;EN-US;889251

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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