Ejemplo n.º 1
0
 /// <summary>
 ///     卸载Windows服务
 /// </summary>
 /// <param name="name"></param>
 public static void Unstall(string name)
 {
     if (Exists(name))
     {
         if (IsStarted(name))
         {
             Stop(name);
         }
         Console.WriteLine("开始卸载服务:");
         Console.WriteLine("--> 服务名称:" + name);
         Console.WriteLine("");
         var ok = false;
         try
         {
             ok = new WinServiceManager().UnInstallService(name);
         }
         catch
         {
         }
         if (ok)
         {
             Console.WriteLine("服务卸载完毕.");
         }
         else
         {
             Console.WriteLine("卸载失败,在卸载过程中发生错误.");
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        ///     安装Windows服务
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="name"></param>
        /// <param name="display"></param>
        /// <param name="description"></param>
        public static void Install(string filePath, string name, string display, string description)
        {
            Console.WriteLine("开始安装服务:");
            Console.WriteLine("--> 服务名称:" + name);
            Console.WriteLine("--> 显示名称:" + display);
            Console.WriteLine("--> 服务描述:" + description);
            Console.WriteLine("");
            var ok = new WinServiceManager().InstallService(filePath, name, display, description);

            if (ok)
            {
                Console.WriteLine("服务安装完毕.");
            }
            else
            {
                Console.WriteLine("安装失败,在安装过程中发生错误,请用管理员模式尝试.");
            }
        }