ASP.NET 进程启动 PowerShell 脚本 IIS 7.5
在我的开发计算机上一切正常,但如果部署到 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();
}
}
}
这是为其运行的应用程序池配置的内容。
过程模型
-> 身份 = 作为域管理员的域用户。
-> 加载用户配置文件 = True
Web App
身份验证是 Windows
我还需要配置什么才能运行该进程?
All works fine on my dev machine but if deployed to IIS the process doesn't get started. I am starting a powershell script by
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();
}
}
}
Here's what's configured for the app pool this is running under.
Process Model
->Identity = domain user who is a Domain Admin.
->Load User Profile = True
Web App
Authentication is Windows
What else do I need to configure to so that I can run the Process?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正如 Start-Automating 建议的那样,我最终这样做了:
在 IIS 服务器上,我执行了以下 powershell 命令“Set-ExecutionPolicy RemoteSigned”
As Start-Automating suggested I eventually ended up doing this:
On the IIS server I executed the following powershell command "Set-ExecutionPolicy RemoteSigned"
最好将 PowerShell API 嵌入调用 .exe
这里有一个旧链接,可以为每个用户提供嵌入在 ASP.NET 中的 PowerShell 运行空间:
http://powershellpipeworks.com/
It's much better to embed the PowerShell APIs the call the .exe
Here's an old link that will get you a PowerShell runspace embedded in ASP.NET per user:
http://powershellpipeworks.com/
检查
powershell.exe
所在文件系统的权限。另外,请检查
事件查看器
中的安全日志
是否存在身份验证错误和访问违规。Check the permissions of the file system where
powershell.exe
lives.Also, check the
Security Log
in theEvent Viewer
for authentication errors and access violations.