• C# 代码重启windows服务


    C# 代码重启windows服务 

     

    C#代码:

    ServiceController service = new ServiceController("wwService");
    protected void btnRestart_Click(object sender, EventArgs e)
        {
            try
            {
                if (service.Status == ServiceControllerStatus.Running)
                {
                    service.Stop();
                    service.WaitForStatus(ServiceControllerStatus.Stopped);
                }
                service.Start();
                service.WaitForStatus(ServiceControllerStatus.Running);

            }
            catch (Exception)
            {
            }
        }

    Web.Config 配置文件:

    如果配置文件不配置这个的话会报一个错误:

    Win32Exception (0x80004005): Access is denied  
    [InvalidOperationException: Cannot open wwService service on computer '.'.]

    <system.web> 
     
    <identity impersonate="true" userName="服务器登录名" password="登录密码"/> 
     
    </system.web>

     原文链接:https://www.cnblogs.com/xiaopin/archive/2012/03/22/2411218.html

  • 相关阅读:
    day10函数嵌套
    day 9
    day 8函数
    day7预习
    合唱队形(解题思维的锻炼)
    Cow Exhibition (背包中的负数问题)
    Investment(完全背包)
    Cash Machine(多重背包二进制转换)
    Milking Time(DP)
    Brackets Sequence(升级版)
  • 原文地址:https://www.cnblogs.com/1175429393wljblog/p/9776833.html
Copyright © 2020-2023  润新知