代码如下: Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
// 这里是关键点,不用Shell启动/重定向输入/重定向输出/不显示窗口
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.WorkingDirectory = "f:\\f";
string command = "cscript.exe";
p.StartInfo.Arguments = "c:\\windows\\system32\\iisapp.vbs /a \"DefaultAppPool\" " + command;
p.Start();
//p.StandardInput.WriteLine("cscript.exe c:\\windows\\system32\\iisapp.vbs /a \"DefaultAppPool\"");
//p.StandardInput.WriteLine("exit");
//p.WaitForExit(60000);
string s = p.StandardOutput.ReadToEnd();// 得到cmd.exe的输出
p.Close();
请多多指教!
p.StartInfo.FileName = "cmd.exe";
// 这里是关键点,不用Shell启动/重定向输入/重定向输出/不显示窗口
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.WorkingDirectory = "f:\\f";
string command = "cscript.exe";
p.StartInfo.Arguments = "c:\\windows\\system32\\iisapp.vbs /a \"DefaultAppPool\" " + command;
p.Start();
//p.StandardInput.WriteLine("cscript.exe c:\\windows\\system32\\iisapp.vbs /a \"DefaultAppPool\"");
//p.StandardInput.WriteLine("exit");
//p.WaitForExit(60000);
string s = p.StandardOutput.ReadToEnd();// 得到cmd.exe的输出
p.Close();
请多多指教!
2、运行cmd /? 看看有哪些参数,应该会有帮助。
p.WaitForExit();
if (p.HasExited)
{
string s = p.StandardOutput.ReadToEnd();
}
而 不是 p.StartInfo.Arguments = command + " c:\\windows\\system32\\iisapp.vbs /a \"DefaultAppPool\" ;
这条命令并不能重新启动应用程序池! WINDOWS SERVER 2003 SP2
(2)你在2003 sp1下正常而在sp2下 报什么错?
WebAppPool.Stop
WebAppPool.Start上面代码保存为VBS脚本文件即可.再用cscript.exe调用一下试试.
没报错,就是没有重起重新启动IIS应用程序池。
程序池名是对的。set WebAppPool = GetObject("IIS://LocalHost/w3svc/AppPools/DefaultAppPool")
WebAppPool.Stop
WebAppPool.Start上面代码保存为VBS脚本文件即可.再用cscript.exe调用一下试试.以上代码是直接在命令提示符下运行还是在 c#代码中运行?估计写在c#中运行也不行吧?权限问题!
有时间再试
把这个相关的网页放到另一个有管理员权限的apppool里面(用localsystem比较方便)
放在计划任务里设了管理员密码执行也不能重起应用程序池。
谁知道怎么回事啊?指点一下!
1.楼主确认你的那段命名是否能够重新启动应用程序池。
关于cmd的调用可以参考这里,
使用C#调用外部Ping命令获取网络连接情况
http://blog.csdn.net/zhzuo/archive/2004/03/21/22024.aspx
2.执行该命令的权限是否足够,可以参考这里。
在.NET代码中模拟特定Windows用户
http://blog.csdn.net/zhzuo/archive/2007/07/18/1698056.aspx如果可以也可以尝试重新启动IIS来实现。
调用iisreset.exe可以很容做到。
毕竟重新启动IIS动作太大
试试这个
[code=BatchFile]
echo off
if exist "%SystemRoot%\Microsoft.NET\Framework\v2.0.50727" goto netOld
:DispError
echo 您的机器上没有安装 .net FrameWork 2.0
pause
goto LastEnd
:netOld
cd %SystemRoot%\Microsoft.NET\Framework\v2.0.50727
echo 您的机器上安装了相应的.net FrameWork,可以运行本脚本,按任意键继续…………
echo off
pause
%SystemRoot%\System32\Cscript %SystemRoot%\System32\iisapp.vbs /a "DefaultAppPool"
:LastEnd
rem exit[/code]另外, 可以参考这个
http://www.microsoft.com/china/technet/community/columns/insider/iisi1104.mspx
The following W3WP.exe processes are serving AppPool: "DefaultAppPool"
W3WP.exe PID:5656
这样子到底有没有重起应用程序池呢?好象没有!
除了:Microsoft (R) Windows Script Host Version 5.6
版权所有(C) Microsoft Corporation 1996-2001。保留所有权利。
什么也没返回!也没重起应用程序池!
p.StartInfo.FileName = "cscript.exe";
p.StartInfo.Arguments = "/c c:\\windows\\system32\\iisapp.vbs /a \"DefaultAppPool\" ;
Process pr = Process.Start(p);
if (pr!=null)
{
......
pr.Dispose();} 想法二:
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments = “/c”command+ "(空一格)c:\\windows\\system32\\iisapp.vbs /a \"DefaultAppPool\" " ;
Process pr = Process.Start(p);
if (pr!=null)
{
......
pr.Dispose();}