简体   繁体   English

如何使用ASP.NET在Windows 2008上执行EXE文件

[英]How to execute EXE file on Windows 2008 using ASP.NET

How to execute EXE file on Windows 2008 using ASP.NET and IIS7? 如何使用ASP.NET和IIS7在Windows 2008上执行EXE文件? I have tried to run code below but it seems do not work. 我试图在下面运行代码,但似乎不起作用。 The code is executed without any error but I do not see Notepad in Processes list. 该代码已执行,没有任何错误,但是在“进程”列表中没有看到记事本。 Everything works fine if I use ASP.NET developer server but not with IIS7. 如果我使用ASP.NET开发人员服务器,但不使用IIS7,则一切正常。

string enginePath = "notepad";

var password = new System.Security.SecureString();
foreach (char character in ConfigurationManager.AppSettings["Credentials"])
    password.AppendChar(character);

var p = new Process
            {
                StartInfo =
                    {
                        FileName = enginePath,    
                        UseShellExecute = false,
                    }
            };


p.StartInfo.UserName = "Administrator";
p.StartInfo.Password = password;

p.Start();

In response to security concerns Microsoft has continually increased the isolation of the IIS process such that you can not (or I have not found a work around which will allow you to...) invoke anything outside the IIS application domain directly. 为了响应安全性考虑,Microsoft不断增加IIS进程的隔离度,以使您无法(或者我没有找到一种解决方法,可以让您...)直接调用IIS应用程序域之外的任何内容。 You can build a Windows service which can use WCF channels to cross that boundary indirectly. 您可以构建Windows服务,该服务可以使用WCF通道间接跨越该边界。 That service (configured to be allowed to interact with the desktop) can in turn launch your Notepad.exe. 该服务(配置为允许与桌面交互)可以反过来启动您的Notepad.exe。

It is a bit of a kludge to make it happen and I will certainly be interested to see if someone else has a better answer. 实现它有点麻烦,我当然会感兴趣的是看看别人是否有更好的答案。

I have removed lines below and it suddenly started working. 我删除了下面的行,它突然开始工作。 I can't explain how it is possible to run exe under IIS7 account but it is working. 我无法解释如何在IIS7帐户下运行exe,但它正在工作。

p.StartInfo.UserName = "Administrator";
p.StartInfo.Password = password;

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

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