【问题标题】:ASP.NET Process Start PowerShell Script IIS 7.5ASP.NET 进程启动 PowerShell 脚本 IIS 7.5
【发布时间】:2011-10-21 20:14:39
【问题描述】:

在我的开发机器上一切正常,但如果部署到 IIS,则进程无法启动。我正在通过

启动一个powershell脚本
    private void RunScript()
    {
        Process process = null;
        try
        {
            int timeout = 1800000;
            var startInfo = new ProcessStartInfo
            {
                FileName = @"powershell.exe",    
                Arguments = string.Format("{0} {1}", "\path\toscript", "myParam"),
                UseShellExecute = false,
                CreateNoWindow = true
            };                   

            process = Process.Start(startInfo);
            process.WaitForExit(timeout);
        }
        finally
        {
            if (!process.HasExited)
            {
                if (process.Responding)
                    process.CloseMainWindow();
                else
                    process.Kill();
            }
            if (process != null)
            {
                process.Close();
                process.Dispose();
            }
        }  
    }

这是为运行该应用程序池配置的内容。

流程模型
->Identity = 作为域管理员的域用户。
->加载用户配置文件 = True

网络应用
身份验证是 Windows

我还需要配置什么才能运行流程?

【问题讨论】:

    标签: asp.net iis-7.5


    【解决方案1】:

    正如 Start-Automating 建议的那样,我最终这样做了:

                using (Runspace runSpace = RunspaceFactory.CreateRunspace())
            {
                try
                {
                    runSpace.Open();
                    RunspaceInvoke scriptInvoker = new RunspaceInvoke(runSpace);
                    scriptInvoker.Invoke("Set-ExecutionPolicy Unrestricted"); 
                    using (Pipeline pipeLine = runSpace.CreatePipeline())
                    {                        
                        var myCommand = new Command(scriptPath);                           
                        var myParam1 = new CommandParameter("-paramName", "someValue"); 
                        myCommand.Parameters.Add(myParam1);
                        pipeLine.Commands.Add(myCommand);       
                        pipeLine.Commands.Add("Out-String");
                        Collection<PSObject> returnObjects = pipeLine.Invoke();
                        runSpace.Close();
    
                        return returnObjects;                                              
                    }
                }
                finally 
                {
                    runSpace.Close();
                }
            }
    

    在 IIS 服务器上,我执行了以下 powershell 命令“Set-ExecutionPolicy RemoteSigned”

    【讨论】:

      【解决方案2】:

      在调用 .exe 时嵌入 PowerShell API 会更好

      这是一个旧链接,可为您提供每个用户嵌入在 ASP.NET 中的 PowerShell 运行空间:

      http://powershellpipeworks.com/

      【讨论】:

        【解决方案3】:

        检查powershell.exe所在文件系统的权限。

        另外,检查Event Viewer 中的Security Log 是否存在身份验证错误和访问违规。

        【讨论】:

        • 正在使用的应用程序池域帐户也是计算机上管理员组的成员。因此,在 C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe 上,Administrators 组具有读取、读取和执行权限。这样的权利就够了吗?
        猜你喜欢
        • 2011-10-30
        • 2010-12-27
        • 1970-01-01
        • 2011-10-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多