尝试运行 psexec 远程连接到服务器并回收应用程序池
如果我从命令提示符运行它,它工作正常。
psexec \ServerName cscript.exe iisapp.vbs /a AppName /r
我正在尝试使用 C# 控制台应用程序执行相同的操作。我正在使用下面的代码,但大多数时候应用程序都会挂起并且无法完成,并且有几次它会抛出错误代码。我这样做错了吗?有谁知道在哪里可以查找错误或错误代码?
static void RecycleAppPool(string sServer)
{
Console.Clear();
ProcessStartInfo p = new ProcessStartInfo("psexec.exe", "\\\\" + sServer + " cscript.exe iisapp.vbs /a <AppName> /r");
p.RedirectStandardInput = true;
p.UseShellExecute = false;
Process.Start(p);
}
当它完成时出现错误,看起来像这样
“cscript.exe 退出,错误代码 -2147024664”
编辑
下面的代码运行良好
static void RecycleAppPool(string sServer)
{
Console.Clear();
ProcessStartInfo p = new ProcessStartInfo("psexec.exe");
p.Arguments = @"\\" + sServer + @" cscript.exe iisapp.vbs /a AppName /r";
p.UseShellExecute = false;
Process.Start(p);
}
If I run this from my command prompt it works fine.
psexec \ServerName cscript.exe iisapp.vbs /a AppName /r
I'm trying to do the same thing with C# console app. I'm using the below code but most of the time the application hangs and doesn't complete, and the few times it does it throws an error code. Am I doing this wrong? Does anyone know where I can look up the error or error code?
static void RecycleAppPool(string sServer)
{
Console.Clear();
ProcessStartInfo p = new ProcessStartInfo("psexec.exe", "\\\\" + sServer + " cscript.exe iisapp.vbs /a <AppName> /r");
p.RedirectStandardInput = true;
p.UseShellExecute = false;
Process.Start(p);
}
When it completes with an error, looks like this
"cscript.exe exited with error code -2147024664"
EDIT
Below code working well
static void RecycleAppPool(string sServer)
{
Console.Clear();
ProcessStartInfo p = new ProcessStartInfo("psexec.exe");
p.Arguments = @"\\" + sServer + @" cscript.exe iisapp.vbs /a AppName /r";
p.UseShellExecute = false;
Process.Start(p);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
VS2003/8/10:工具->错误查找。粘贴十六进制的错误代码。 800700E8。这是“管道正在关闭”。不是很有帮助 - 我猜重定向存在一些问题。
您是否真的有 ProcessStartInfo 参数,或者该参数用于替换您的实际应用程序名称?
VS2003/8/10: Tools->Error Lookup. Paste in the error code in hex. 800700E8. It's "The pipe is being closed." Not very helpful - some issue with redirection i guess.
Do you really have in the ProcessStartInfo parameter, or is that being used to replace what your actual app name is?
您是否尝试过使用 appcmd 而不是 iisapp 进行回收.vbs?
并且,在此 线程 中,他们使用 WMI 回收了远程应用程序池。
Have you tried recycling using appcmd instead of iisapp.vbs?
And, in this thread they recycled a remote application pool using WMI.
如果是 IIS7,那么您可以从 C# 访问 Web 管理命名空间:
您可以了解有关 此处的 Web 管理命名空间。到目前为止,它对我们来说效果很好。但必须安装在客户端和远程计算机上。
If it's IIS7 then you can you the web admin namespace from C#:
You can learn more about the Web Admin Namespace here. So far it has worked very well for us. BUT must be installed on the client and remote machines.
在过去的两天里,我在这个问题上苦苦挣扎,尝试了我在网上找到的每一个解决方案。我正在尝试回收不同域中远程计算机上的应用程序池。我尝试使用 PsExec 的第一种方法返回了错误 3。我尝试了 DirectoryEntry,但权限也失败,然后尝试使用 ServerManager 但出现同样的问题。
最后,我转向 WMI 并且它起作用了:
希望这会有所帮助。
I struggled with this a lot for the last 2 days trying every solution I found online. I'm trying to recycle an application pool on remote machines on a different domain. The first method I tried with PsExec returned error 3. I tried DirectoryEntry and failed on permissions as well and then tried using ServerManager but the same issue.
Finally, I moved to WMI and it worked:
Hope this helps.