首页 技术 正文
技术 2022年11月21日
0 收藏 685 点赞 2,599 浏览 2349 个字

重启站点:

 /// <summary>
/// 根据名字重启站点.(没重启线程池)
/// </summary>
/// <param name="sitename"></param>
static void RestartWEbSite(string sitename)
{
try
{
var server = new ServerManager();
var site = server.Sites.FirstOrDefault(s => s.Name == sitename);
if (site != null)
{
site.Stop();
if (site.State == ObjectState.Stopped)
{
}
else
{
Console.WriteLine("Could not stop website!");
throw new InvalidOperationException("Could not stop website!");
}
site.Start();
}
else
{
Console.WriteLine("Could not find website!");
throw new InvalidOperationException("Could not find website!");
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
/// <summary>
/// 重启完之后.要再检测下.是否开启了
/// </summary>
/// <param name="sitename"></param>
static void FixWebsite(string sitename)
{
try
{
var server = new ServerManager();
var site = server.Sites.FirstOrDefault(s => s.Name == sitename);
if (site != null)
{
if (site.State != ObjectState.Started)
{
Thread.Sleep();
//防止状态为正在开启
if (site.State != ObjectState.Started)
{
site.Start();
}
}
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
}

重启iis线程池:

/// <summary>
/// 线程池名字
/// </summary>
/// <param name="name"></param>
static void RestartIISPool(string name)
{
string[] cmds = { "c:", @"cd %windir%\system32\inetsrv", string.Format("appcmd stop apppool /apppool.name:{0}", name), string.Format("appcmd start apppool /apppool.name:{0}", name) };
Cmd(cmds);
CloseProcess("cmd.exe");
}
/// <summary>
/// 运行CMD命令
/// </summary>
/// <param name="cmd">命令</param>
/// <returns></returns>
public static string Cmd(string[] cmd)
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.StandardInput.AutoFlush = true;
for (int i = ; i < cmd.Length; i++)
{
p.StandardInput.WriteLine(cmd[i]);
}
p.StandardInput.WriteLine("exit");
string strRst = p.StandardOutput.ReadToEnd(); //Debug.Print(strRst);
p.WaitForExit();
p.Close();
return strRst;
}
/// <summary>
/// 关闭进程
/// </summary>
/// <param name="ProcName">进程名称</param>
/// <returns></returns>
public static bool CloseProcess(string ProcName)
{
bool result = false;
var procList = new ArrayList();
foreach (Process thisProc in Process.GetProcesses())
{
var tempName = thisProc.ToString();
int begpos = tempName.IndexOf("(") + ;
int endpos = tempName.IndexOf(")");
tempName = tempName.Substring(begpos, endpos - begpos);
procList.Add(tempName);
if (tempName == ProcName)
{
if (!thisProc.CloseMainWindow())
thisProc.Kill(); // 当发送关闭窗口命令无效时强行结束进程
result = true;
}
}
return result;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,943
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,469
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,283
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,098
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,729
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,766