Ejemplo n.º 1
0
        public static void CreateService(string serviceName, string binPath, WinServiceServiceAccountInfo accountInfo, params string[] dependsOn)
        {
            if (System.ServiceProcess.ServiceController.GetServices().Any(s => string.Compare(s.ServiceName, serviceName, true) == 0))
            {
                return;
            }

            string depend = string.Empty;

            if (dependsOn != null && dependsOn.Length > 0)
            {
                depend = string.Format("depend= {0}", string.Join("/", dependsOn));
            }


            string account = string.Empty;

            if (accountInfo != null && !string.IsNullOrEmpty(accountInfo.UserName))
            {
                if (string.IsNullOrEmpty(accountInfo.Password))
                {
                    account = string.Format("obj= {0}", accountInfo.UserName);
                }
                else
                {
                    account = string.Format("obj= {0} password= {1}", accountInfo.UserName, accountInfo.Password);
                }
            }

            Run(string.Format(" create {0} binPath= {1} start= auto {2} {3}", serviceName, binPath, depend, account));
        }
Ejemplo n.º 2
0
 public void CreateService(string serviceName, string binPath, WinServiceServiceAccountInfo accountInfo, params string[] dependsOn)
 {
     ServiceControlUtils.CreateService(serviceName, binPath, accountInfo, dependsOn);
 }