/// <summary>
        /// </summary>
        /// <param name="objz"></param>
        /// <param name="cmdTag"></param>
        /// <returns></returns>
        public static bool ChangeServiceStartMode(WmiServiceObj objz, string cmdTag)
        {
            bool bRel;
            var sc = new ServiceController(objz.Name);
            string startupType = "";

            var myPath = new ManagementPath
            {
                Server = Environment.MachineName,
                NamespacePath = @"root\CIMV2",
                RelativePath = string.Format("Win32_Service.Name='{0}'", sc.ServiceName)
            };
            switch (cmdTag)
            {
                case "41":
                    startupType = "Manual";
                    break;
                case "42":
                    startupType = "Auto";
                    break;
                case "43":
                    startupType = "Disabled";
                    break;
            }
            using (var service = new ManagementObject(myPath))
            {
                ManagementBaseObject inputArgs = service.GetMethodParameters("ChangeStartMode");
                inputArgs["startmode"] = startupType;
                service.InvokeMethod("ChangeStartMode", inputArgs, null);
                bRel = true;
            }

            sc.Refresh();
            return bRel;
        }
        /// <summary>
        /// </summary>
        /// <param name="objz"></param>
        /// <param name="sMessage"></param>
        /// <returns></returns>
        public static bool DeleteService(WmiServiceObj objz, out string sMessage)
        {
            bool bRel;
            var sc = new ServiceController(objz.Name);

            var myPath = new ManagementPath
            {
                Server = Environment.MachineName,
                NamespacePath = @"root\CIMV2",
                RelativePath = string.Format("Win32_Service.Name='{0}'", sc.ServiceName)
            };

            using (var service = new ManagementObject(myPath))
            {
                ManagementBaseObject outParams = service.InvokeMethod("delete", null, null);
                sMessage = outParams["ReturnValue"].ToString();
                bRel = true;
            }

            sc.Refresh();
            return bRel;
        }
 public WorkThread(WmiServiceObj dsvc)
 {
     _objBiz = dsvc;
 }
 /// <summary>
 ///     Shell
 /// </summary>
 /// <param name="objz"></param>
 public static void ExplorerPath(WmiServiceObj objz)
 {
     DirectoryInfo adi;
     FileHelper.GetShortDirAndSetDirInfo(objz.Path, out adi);
     string sPath = Environment.GetEnvironmentVariable("windir");
     Process.Start(string.Format("{0}{1}Explorer.exe", sPath, Path.DirectorySeparatorChar), adi.FullName);
 }
        /// <summary>
        /// </summary>
        /// <param name="objz"></param>
        /// <param name="scs"></param>
        /// <param name="arRef">for check service startmode</param>
        /// <returns></returns>
        public static bool SwitchServiceStatusTo(WmiServiceObj objz, ServiceControllerStatus scs)
        {
            var sc = new ServiceController(objz.Name);

            switch (scs)
            {
                case ServiceControllerStatus.Running:
                    if (objz.StartMode.ToLower() != "disabled")
                    {
                        sc.Start();
                        return true;
                    }
                    break;
                    break;
                case ServiceControllerStatus.Stopped:
                    if (sc.CanStop)
                    {
                        sc.Stop();
                        Console.WriteLine("Service {0} stoped", sc.ServiceName);
                        return true;
                    }
                    break;
            }

            sc.Refresh();
            return false;
        }
        public static bool SwitchServiceStatusTo(WmiServiceObj objBiz)
        {
            var sc = new ServiceController(objBiz.Name);
            if (sc.Status == ServiceControllerStatus.Running)
            {
                if (sc.CanStop)
                {
                    sc.Stop();
                    Console.WriteLine("Service {0} stoped", sc.ServiceName);
                    return true;
                }
            }
            else
            {
                if (objBiz.StartMode.ToLower() != "disabled")
                {
                    sc.Start();
                    return true;
                }
            }

            sc.Refresh();
            return false;
        }