Exemple #1
0
        /// <summary>
        /// 服务安装
        /// </summary>
        /// <param name="serviceInfo"></param>
        public void Install(ServiceInstallInfoListModel installInfos)
        {
            if (installInfos == null ||
                installInfos.ServiceInstallInfos == null ||
                installInfos.ServiceInstallInfos.Length == 0)
            {
                throw new ArgumentNullException("installInfos"
                                                , TextManager.DefaultInstance.GetTextWithTail(Texts.DotNetServiceInstaller_05));
            }
            ServiceInstallerHelper installerHelp = new ServiceInstallerHelper();

            for (Int32 i = 0; i < installInfos.ServiceInstallInfos.Length; i++)
            {
                try
                {
                    this.Install(installInfos.ServiceInstallInfos[i]);
                }
                catch
                {
                    throw;
                }
            }
        }
 /// <summary>
 /// 服务安装
 /// </summary>
 /// <param name="serviceInfo"></param>
 public void Install(ServiceInstallInfoListModel installInfos)
 {
     if (installInfos == null
         || installInfos.ServiceInstallInfos == null
         || installInfos.ServiceInstallInfos.Length == 0)
         throw new ArgumentNullException("installInfos"
                                        , TextManager.DefaultInstance.GetTextWithTail(Texts.DotNetServiceInstaller_05));
     ServiceInstallerHelper installerHelp = new ServiceInstallerHelper();
     for (Int32 i = 0; i < installInfos.ServiceInstallInfos.Length; i++)
     {
         try
         {
             this.Install(installInfos.ServiceInstallInfos[i]);
         }
         catch
         {
             throw;
         }
     }
 }
        /// <summary>
        /// 服务卸载
        /// </summary>
        /// <param name="serviceName"></param>
        public void UnInstall(String serviceName, String logFilePath)
        {
            if (String.IsNullOrWhiteSpace(serviceName))
                throw new ArgumentNullException("serviceName"
                                               , TextManager.DefaultInstance.GetTextWithTail(Texts.DotNetServiceInstaller_08));
            if (!((Boolean)CheckServiceState(serviceName)["IfExists"]))
                throw new InvalidOperationException(TextManager.DefaultInstance.GetTextWithTail(Texts.DotNetServiceInstaller_09
                                                                                      , serviceName));

            if (!String.IsNullOrEmpty(logFilePath))
                logFilePath = Path.GetFullPath(logFilePath);
            ServiceInstallerHelper installerHelp = new ServiceInstallerHelper();
            installerHelp.ServiceName = serviceName;
            installerHelp.InstallLogFilePath = logFilePath;
            installerHelp.Uninstall(null);
        }
        /// <summary>
        /// 服务安装
        /// </summary>
        /// <param name="installInfo"></param>
        public void Install(ServiceInstallInfo installInfo)
        {
            if (installInfo == null
                || String.IsNullOrWhiteSpace(installInfo.ServiceName)
                || String.IsNullOrWhiteSpace(installInfo.ServiceFilePath))
                throw new ArgumentNullException("installInfo"
                                               , TextManager.DefaultInstance.GetTextWithTail(Texts.DotNetServiceInstaller_02));

            ServiceInstallerHelper installerHelp = new ServiceInstallerHelper();
            try
            {
                installerHelp.ServiceFilePath = installInfo.ServiceFilePath;
                installerHelp.ServiceName = installInfo.ServiceName;
                installerHelp.DisplayName = installInfo.DisplayName;
                installerHelp.Description = installInfo.Description;
                installerHelp.StartType = installInfo.StartType;
                installerHelp.IfDelayedAutoStart = installInfo.IfDelayedAutoStart;
                installerHelp.ServicesDependedOn = installInfo.ServicesDependedOn;
                installerHelp.InstallLogFilePath = installInfo.InstallLogFilePath;
                installerHelp.ServiceAccount = installInfo.ServiceAccount.Account;
                installerHelp.UserName = installInfo.ServiceAccount.UserName;
                installerHelp.Password = installInfo.ServiceAccount.Password;
                installerHelp.Install(new Hashtable());
                if (installInfo.IfStartAfterInstall)
                {
                    try
                    {
                        using (ServiceController controller = new ServiceController(installInfo.ServiceName))
                        {
                            controller.Start();
                            controller.Close();
                        }
                    }
                    catch { }
                }
            }
            catch
            {
                throw;
            }
        }