需要在ASP.net中的服务器上执行*.exe

san*_*h.v 16 windows asp.net web-services windows-server-2008

我目前的情况是我需要在IIS托管ASP.net/C# API的远程服务器上执行exe(它创建一个本地.txt文件).我创建了一个本地用户(比如userA)作为管理员来运行远程服务器中的Web服务,但是没有创建.txt文件.我已经检查并向userA授予必要的文件夹权限,并将用户添加到各个组中.有趣的是,如果我以远程系统中的userA身份登录,则exe会按预期执行.如果我退出然后它失败了.服务器是带有IIS 7的Win服务器2008.任何帮助将不胜感激.

更新:我已经解决了这个问题,并在此处发布了相关问题的答案和一些链接.简而言之,我需要在IIS应用程序池中设置"加载用户配置文件".

谢谢大家的贡献

san*_*h.v 12

更新:几周后我设法解决了这个问题.谢谢大家的贡献.显然,IIS默认情况下不会加载Windows用户配置文件.因此,当作为未登录的其他用户运行时,他们的Windows配置文件必须由IIS加载.在应用程序池的高级设置菜单中,有一个选项"加载窗口配置文件"我只是将其更改为true.在IIS的早期版本中,默认情况下将其设置为"true".

有关同一解决方案的SO的相关问题:

1)IIS 7.5中的安全性异常和IIS 7.5中的"加载用户配置文件"选项

2)在IIS7上运行asp.net Web应用程序项目会引发异常

3)新部署的System.Web.AspNetHostingPermission异常

另一个4)http://geekswithblogs.net/ProjectLawson/archive/2009/05/05/iis-system.web.aspnethostingpermission-exception-on-windows-7-rc.aspx


小智 7

您可以使用Process.Start

Process process = new Process();
process.StartInfo.FileName = "CVS.exe";
process.StartInfo.Arguments = "if any";
process.Start();
Run Code Online (Sandbox Code Playgroud)

还有一篇关于在asp.net中作为另一个用户运行进程的帖子:

http://weblogs.asp.net/hernandl/archive/2005/12/02/startprocessasuser.aspx

提供用户凭证

简而言之,它表示您必须重定向该过程,使用以下代码:

ProcessStartInfo info = new ProcessStartInfo("cmd.exe");

info.UseShellExecute = false;

info.RedirectStandardInput = true;

info.RedirectStandardError = true;

info.RedirectStandardOutput = true;

info.UserName = dialog.User; // see the link mentioned at the top

info.Password = dialog.Password;

using (Process install = Process.Start(info))

{

      string output = install.StandardOutput.ReadToEnd();

      install.WaitForExit();

      // Do something with you output data

      Console.WriteLine(output);

}
Run Code Online (Sandbox Code Playgroud)