需要从 ASP.net 在服务器中执行 *.exe [英] Need to execute *.exe in server from ASP.net

查看:19
本文介绍了需要从 ASP.net 在服务器中执行 *.exe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

My current situation is that I need to execute an exe(which creates a local .txt file) in remote server with IIS hosting an ASP.net/C# API. I created a local user(say userA) as admin to run the web service in the remote server but the .txt file was not created. I already checked and granted necessary folder permissions to userA and added the user in various groups. The funny thing is that if i am logged in as userA in the remote system, the exe gets executed as expected. If i log out then it fails. Server is Win server 2008 with IIS 7. Any help would be appreciated thanks.

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

UPDATE: I've solved the issue and posted the answer and a few links to related issues here on SO. In short, I needed to set 'load user profile' true in IIS app pool.

感谢大家的贡献

从评论中提取的代码

Process proc = new Process(); 
proc.StartInfo.FileName = path; 
proc.StartInfo.Arguments = exeparams; 
proc.Start(); 
proc.WaitForExit(); 
stat = proc.ExitCode; 
if (stat != 0) 
{ 
    throw new Functions.log("Error"); 
} 

推荐答案

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

UPDATE: I managed to solve the issue after many weeks. Thank you all for your contribution. Apparently IIS does not load windows user profiles by default. So when running as a different user who is not logged on, their windows profile must be loaded by IIS. In advanced setting menu of your app pool, there is an option "load windows profile" I just changed this to true. In prior versions of IIS, this was set to 'true' by default.

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

Related questions on SO with same solution:

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

2) 运行asp.netIIS7 上的 web 应用程序项目抛出异常

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

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

这篇关于需要从 ASP.net 在服务器中执行 *.exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆