2011-10-21 90 views
2

所有的作品在我的dev的机器上正常,但如果部署到IIS进程不上手。我正在启动一个PowerShell脚本ASP.NET进程开始PowerShell脚本IIS 7.5

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(); 
      } 
     } 
    } 

以下是为此应用程序池配置的内容。

过程模型
- >身份=谁是域管理员域用户。
- >加载用户配置=真

Web App的
身份验证的Windows

还有什么我需要配置,这样我可以运行过程?

回答

0

检查文件系统中powershell.exe生活的权限。

此外,检查Event ViewerSecurity Log认证错误和访问冲突。

+0

正在使用的应用程序池域帐户也是在机器上管理员组的成员。所以,在C:\ WINDOWS \ SYSTEM32 \ WindowsPowerShell \ V1.0 \ powershell.exe Administrators组具有读取,读取和执行权限。这是足够的权利吗? – dm80

2

由于启动自动化建议我最终结束了这样做:

  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的COM普通话“设置-ExecutionPolicy RemoteSigned就是”