コード例 #1
0
 static void Install(bool undo, string[] args)
 {
     using (AssemblyInstaller asminstall = new AssemblyInstaller(typeof(XenService).Assembly, args))
     {
         System.Collections.IDictionary state = new System.Collections.Hashtable();
         asminstall.UseNewContext = true;
         try
         {
             if (undo)
             {
                 asminstall.Uninstall(state);
             }
             else
             {
                 asminstall.Install(state);
                 asminstall.Commit(state);
             }
         }
         catch
         {
             try
             {
                 asminstall.Rollback(state);
             }
             catch { }
         }
     }
 }
コード例 #2
0
        /// <summary>
        /// Installs or uninstalls the lwshost service
        ///
        /// Source: https://groups.google.com/forum/#!topic/microsoft.public.dotnet.languages.csharp/TUXp6lRxy6Q
        /// </summary>
        /// <param name="undo">revert installation</param>
        public static EHostServiceInstallState Install(bool undo = false)
        {
            using (AssemblyInstaller inst = new AssemblyInstaller(typeof(Program).Assembly, new string[0]))
            {
                IDictionary state = new Hashtable();
                inst.UseNewContext = true;

                try
                {
                    if (undo)
                    {
                        inst.Uninstall(state);
                        return(EHostServiceInstallState.UninstalCompleted);
                    }
                    else
                    {
                        inst.Install(state);
                        inst.Commit(state);
                        return(EHostServiceInstallState.InstallAndCommitCompleted);
                    }
                }
                catch
                {
                    try
                    {
                        inst.Rollback(state);
                        return(EHostServiceInstallState.RollbackCompleted);
                    }
                    catch
                    {
                        return(EHostServiceInstallState.RollbackFailed);
                    }
                }
            }
        }
コード例 #3
0
        private static void InstallService(ISLogger logger)
        {
            if (IsInstalled())
            {
                Console.WriteLine("Try to install collection service but, service already installed! ");
                logger.Debug("Try to install collection service but, service already installed! ");
                return;
            }

            logger.Debug("Install collection service... ");

            AssemblyInstaller installer = GetInstaller(logger);
            IDictionary       state     = new Hashtable();

            try
            {
                installer.Install(state);
                installer.Commit(state);
            }
            catch (Exception e)
            {
                Console.WriteLine("Install CollectionService error " + e.Message);
                logger.Error("Install CollectionService error " + e.Message);
                logger.Error(e.ToString());
            }
            finally
            {
                try { installer.Rollback(state); } catch { };
            }
        }
コード例 #4
0
        public static void InstallService(string serviceName, Assembly assembly)
        {
            if (IsServiceInstalled(serviceName))
            {
                return;
            }

            using (AssemblyInstaller installer = GetInstaller(assembly))
            {
                IDictionary state = new Hashtable();
                try
                {
                    installer.Install(state);
                    installer.Commit(state);
                }
                catch
                {
                    try
                    {
                        installer.Rollback(state);
                    }
                    catch { }
                    throw;
                }
            }
        }
コード例 #5
0
        private static void InstallService()
        {
            if (IsInstalled())
            {
                return;
            }

            try
            {
                using (AssemblyInstaller installer = GetInstaller())
                {
                    IDictionary state = new Hashtable();
                    try
                    {
                        installer.Install(state);
                        installer.Commit(state);
                    }
                    catch
                    {
                        try { installer.Rollback(state); }
                        catch { }
                        throw;
                    }
                }
            }
            catch { throw; }
        }
コード例 #6
0
ファイル: ServiceAppInstaller.cs プロジェクト: rrs/ServiceApp
        public static void Install(string serviceName, bool undo, string[] args, string serviceDisplayName = null, string description = null)
        {
            try
            {
                Console.WriteLine(undo ? "uninstalling" : "installing");
                using (var inst = new AssemblyInstaller(Assembly.GetEntryAssembly(), args))
                {
                    var processInstaller = new ServiceProcessInstaller
                    {
                        Account = ServiceAccount.LocalSystem
                    };

                    var serviceInstaller = new System.ServiceProcess.ServiceInstaller
                    {
                        StartType   = ServiceStartMode.Automatic,
                        ServiceName = serviceName,
                        DisplayName = serviceDisplayName ?? Regex.Replace(serviceName, "(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])", " "),
                        Description = description
                    };

                    inst.Installers.Add(processInstaller);
                    inst.Installers.Add(serviceInstaller);

                    IDictionary state = new Hashtable();
                    inst.UseNewContext = true;
                    try
                    {
                        if (undo)
                        {
                            var sc = new ServiceController(serviceName);
                            if (sc.Status == ServiceControllerStatus.Running)
                            {
                                sc.Stop();
                            }
                            inst.Uninstall(state);
                        }
                        else
                        {
                            inst.BeforeInstall += (s, e) => { inst.Context.Parameters["assemblyPath"] = $@"""{inst.Context.Parameters["assemblyPath"]}"" --service"; };
                            inst.AfterInstall  += (s, e) => { new ServiceController(serviceName).Start(); };
                            inst.Install(state);
                            inst.Commit(state);
                        }
                    }
                    catch
                    {
                        try
                        {
                            inst.Rollback(state);
                        }
                        catch { }
                        throw;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.Message);
            }
        }
コード例 #7
0
ファイル: InstallUtil.cs プロジェクト: zhang13634419004/Tools
 private void TryRollback(AssemblyInstaller installer, IDictionary state)
 {
     try { installer.Rollback(state); }
     catch (Exception ex)
     {
         _log.Write(LogLevel.Warning, "An error occured during rollback. {0}", ex);
     }
 }
コード例 #8
0
        private static void handleInstallService(bool remove, string[] args)
        {
            try
            {
                using (var inst = new AssemblyInstaller(typeof(Program).Assembly, args))
                {
                    IDictionary state = new Hashtable();
                    inst.UseNewContext = true;
                    try
                    {
                        if (remove)
                        {
                            Log.Write("Removing the service...");
                            Log.WriteLine("------------------------");
                            inst.Uninstall(state);
                        }
                        else
                        {
                            Log.Write("Installing the service...");
                            Log.WriteLine("");
                            Log.WriteLine("NOTICE The service will not be active");
                            Log.WriteLine("Please check your configuration before starting. ");
                            Log.WriteLine("To start the service, execute: ");
                            Log.WriteLine(typeof(Program).Assembly.Location + " start");
                            Log.WriteLine("");
                            Log.WriteLine("------------------------");
                            inst.Install(state);
                        }
                        inst.Commit(state);
                        Log.WriteLine("Success");
                    }
                    catch (Exception exception)
                    {
                        Log.WriteLine("Failed: " + exception.Message);
                        try
                        {
                            Log.WriteLine("Rolling back...");
                            inst.Rollback(state);
                            Log.WriteLine("Rollback was successful");
                        }
                        catch (Exception exceptionRollBack)
                        {
                            Log.WriteLine("Rollback Failed: " + exceptionRollBack.Message);
                        }

                        throw;
                    }
                }
            }
            catch (Exception ex)
            {
                Log.WriteLine(ex.Message);
            }
        }
コード例 #9
0
        public static bool Install()
        {
            Tracker.StartServer();

            bool result = true;

            InstallContext context = null;

            try
            {
                using (var inst = new AssemblyInstaller(typeof(ServerLifecycleManager).Assembly, null))
                {
                    context = inst.Context;
                    LogMessage("Installing service " + AppSettings.ServiceName, inst.Context);
                    IDictionary state = new Hashtable();
                    inst.UseNewContext = true;

                    try
                    {
                        inst.Install(state);
                        inst.Commit(state);
                        Tracker.TrackEvent(TrackerEventGroup.Installations, TrackerEventName.Installed);
                    }
                    catch (Exception err)
                    {
                        Tracker.TrackException("WindowsServiceManager", "Install", err);
                        try
                        {
                            inst.Rollback(state);
                        }
                        catch (Exception innerErr)
                        {
                            throw new AggregateException(new List <Exception> {
                                err, innerErr
                            });
                        }
                        throw;
                    }
                }
            }
            catch (Exception ex)
            {
                result = false;
                WriteExceptions(ex, context);
            }
            finally
            {
                Tracker.Stop();
            }

            return(result);
        }
コード例 #10
0
 // This is the method that does the actual installing/uninstalling of the service for Windows
 static void Install(bool uninstall, string[] args)
 {
     try
     {
         Console.WriteLine(uninstall ? "Uninstalling Service" : "Installing Service");
         using (AssemblyInstaller inst = new AssemblyInstaller(typeof(MyProjectInstaller).Assembly, args))
         {
             IDictionary state = new Hashtable();
             inst.UseNewContext = true;
             try
             {
                 if (uninstall)
                 {
                     inst.Uninstall(state);
                     Console.WriteLine();
                     Console.WriteLine("Uninstall Successful");
                 }
                 else
                 {
                     inst.Install(state);
                     Console.WriteLine();
                     Console.WriteLine("Installed Successfuly. Now Commiting...");
                     inst.Commit(state);
                     Console.WriteLine();
                     Console.WriteLine("Commit Successful");
                 }
             }
             catch (Exception ex)
             {
                 try
                 {
                     Console.WriteLine();
                     Console.WriteLine("ERROR: " + ex.Message);
                     Console.WriteLine();
                     Console.WriteLine("Rolling back service installation...");
                     inst.Rollback(state);
                     Console.WriteLine();
                     Console.WriteLine("Rollback Successful");
                 }
                 catch { }
                 throw;
             }
         }
     }
     catch (Exception ex)
     {
         Console.Error.WriteLine(ex.Message);
     }
 }
コード例 #11
0
ファイル: Program.cs プロジェクト: akshaynm87/FamServer
        static void Install(bool undo, string[] args)
        {
            try
            {
                Console.WriteLine(undo ? "uninstalling" : "installing");
                using (AssemblyInstaller inst = new AssemblyInstaller(typeof(Program).Assembly, args))
                {
                    IDictionary state = new Hashtable();
                    inst.UseNewContext = true;
                    try
                    {
                        if (undo)
                        {
                            inst.Uninstall(state);
                        }
                        else
                        {
                            inst.Install(state);
                            inst.Commit(state);
                            try
                            {
                                ServiceController service = new ServiceController("DpFamService");
                                TimeSpan          timeout = TimeSpan.FromMilliseconds(1000);

                                service.Start();
                                service.WaitForStatus(ServiceControllerStatus.Running, timeout);
                            }
                            catch
                            {
                                Console.WriteLine("Could not start the server\n");
                            }
                        }
                    }
                    catch
                    {
                        try
                        {
                            inst.Rollback(state);
                        }
                        catch { }
                        throw;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.Message);
            }
        }
コード例 #12
0
        public void OnAction(Hashtable parameters)
        {
            ArrayList temp = new ArrayList();

            temp.Add("/LogToConsole=false");
            StringBuilder tempString = new StringBuilder();

            foreach (DictionaryEntry entry in parameters)
            {
                if (tempString.Length > 0)
                {
                    tempString.Append(" ");
                }

                tempString.Append(entry.Key);
                tempString.Append("=");
                tempString.Append(entry.Value);
            }

            temp.Add("commandline=" + tempString.ToString());

            string[] commandLine = (string[])temp.ToArray(typeof(string));

            System.Configuration.Install.AssemblyInstaller asmInstaller = new AssemblyInstaller(Assembly.GetExecutingAssembly(), commandLine);
            Hashtable rollback = new Hashtable();

            if (GameServerService.GetDOLService() != null)
            {
                Console.WriteLine("DOL service is already installed!");
                return;
            }

            Console.WriteLine("Installing DOL as system service...");
            try
            {
                asmInstaller.Install(rollback);
                asmInstaller.Commit(rollback);
            }
            catch (Exception e)
            {
                asmInstaller.Rollback(rollback);
                Console.WriteLine("Error installing as system service");
                Console.WriteLine(e.Message);
                return;
            }

            Console.WriteLine("Finished!");
        }
コード例 #13
0
        public static void Setup(SetupOperation operation, string[] args)
        {
            AssemblyInstaller installer = GetInstaller(args);

            try
            {
                IDictionary state = new Hashtable();
                switch (operation)
                {
                case SetupOperation.Install:
                    try
                    {
                        installer.Install(state);
                        installer.Commit(state);
                    }
                    catch (Exception e)
                    {
                        installer.Rollback(state);
                        MessageHandler.HandleError("Error during the installation, it has been rolled back", 0, e);
                    }
                    break;

                case SetupOperation.Uninstall:
                    installer.Uninstall(state);
                    break;
                }
            }
            catch (InstallException ie)
            {
                MessageHandler.HandleError("An error occurred while setting up the system", 0, ie);
            }
            catch (System.Security.SecurityException se)
            {
                MessageHandler.HandleError("Administrator permissions are required to set up the service", 0, se);
            }
            catch (Exception e)
            {
                MessageHandler.HandleError("An unknown error occurred while setting up the service", 0, e);
            }
            finally
            {
                if (installer != null)
                {
                    installer.Dispose();
                }
            }
        }
コード例 #14
0
        /// <summary>
        /// Installation standalone du service.
        /// </summary>
        /// <param name="undo"></param>
        /// <param name="args"></param>
        public static void Install(bool undo, string[] args)
        {
            // Source: https://groups.google.com/forum/?hl=en&fromgroups=#!topic/microsoft.public.dotnet.languages.csharp/TUXp6lRxy6Q
            var logger = LogManager.GetLogger("MemcachedServiceInstaller");

            try
            {
                logger.Info(undo ? "uninstalling" : "installing");
                using (AssemblyInstaller inst = new
                                                AssemblyInstaller(typeof(MemcachedServiceInstaller).Assembly, args))
                {
                    IDictionary state = new Hashtable();
                    inst.UseNewContext = true;
                    try
                    {
                        if (undo)
                        {
                            inst.Uninstall(state);
                        }
                        else
                        {
                            inst.Install(state);
                            inst.Commit(state);
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.ToString());
                        try
                        {
                            inst.Rollback(state);
                        }
                        catch (Exception ex2)
                        {
                            logger.Error(ex2.ToString());
                        }
                        throw;
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Fatal(ex.ToString());
                throw;
            }
        }
コード例 #15
0
 internal static void Uninstall(string[] args)
 {
     ServiceInstaller.StopService();
     using (AssemblyInstaller inst = new AssemblyInstaller(typeof(Program).Assembly, args))
     {
         IDictionary state = new Hashtable();
         inst.UseNewContext = true;
         try
         {
             inst.Uninstall(state);
         }
         catch (Exception ex)
         {
             inst.Rollback(state);
             throw ex;
         }
     }
 }
コード例 #16
0
        public void Uninstall()
        {
            var installer = new AssemblyInstaller(Assembly.GetExecutingAssembly(), null)
            {
                UseNewContext = true
            };
            var state = new Hashtable();

            try
            {
                installer.Uninstall(state);
            }
            catch
            {
                installer.Rollback(state);
                throw;
            }
        }
コード例 #17
0
 // References http://stackoverflow.com/questions/1195478/how-to-make-a-net-windows-service-start-right-after-the-installation/1195621#1195621
 public static void Install()
 {
     using (AssemblyInstaller installer =
                new AssemblyInstaller(typeof(OpenVpnService).Assembly, null))
     {
         installer.UseNewContext = true;
         var state = new System.Collections.Hashtable();
         try
         {
             installer.Install(state);
             installer.Commit(state);
         } catch
         {
             installer.Rollback(state);
             throw;
         }
     }
 }
コード例 #18
0
        private void DoInstall(bool add, string[] args)
        {
            try
            {
                this.CbLog(add ? "Installing application..." : "Uninstalling application...");
                this.CbLog("This must be run as an Administrator!");

                using (AssemblyInstaller inst = new AssemblyInstaller(
                           this.ProgramToInstall.Assembly, args))
                {
                    IDictionary state = new Hashtable();
                    inst.UseNewContext = true;

                    try
                    {
                        if (add)
                        {
                            inst.Install(state);
                            inst.Commit(state);
                        }
                        else
                        {
                            inst.Uninstall(state);
                        }

                        this.CbLog("Installation successful!");
                    }
                    catch
                    {
                        this.CbLog("Installation error:");
                        try
                        {
                            inst.Rollback(state);
                        }
                        catch { }
                        throw;
                    }
                }
            }
            catch (Exception ex)
            {
                this.CbLog(ex);
            }
        }
コード例 #19
0
        private void Install(bool install)
        {
            try
            {
                _installLog.Info(install ? "Installing" : "Uninstalling");
                using (var inst = new AssemblyInstaller(typeof(Program).Assembly, null))
                {
                    IDictionary state = new Hashtable();
                    inst.UseNewContext = true;

                    try
                    {
                        EnsureEveryoneHasPermissionsToWriteToLogFiles();

                        if (install)
                        {
                            inst.Install(state);
                            inst.Commit(state);
                        }
                        else
                        {
                            inst.Uninstall(state);
                        }
                    }
                    catch
                    {
                        try
                        {
                            inst.Rollback(state);
                        }
                        catch (Exception ex)
                        {
                            _installLog.Error("Error Rolling back");
                            _installLog.Error(ex.Message);
                        }
                        throw;
                    }
                }
            }
            catch (Exception ex)
            {
                ReportError(ex);
            }
        }
コード例 #20
0
        internal static void Install(bool undo, string[] args)
        {
            try
            {
                Console.WriteLine(undo ? "uninstalling" : "installing");

                using (AssemblyInstaller inst =
                           new AssemblyInstaller(typeof(Program).Assembly, args))
                {
                    IDictionary state = new Hashtable();
                    inst.UseNewContext = true;
                    try
                    {
                        if (undo)
                        {
                            inst.Uninstall(state);
                        }
                        else
                        {
                            inst.Install(state);
                            inst.Commit(state);
                        }
                    }
                    catch
                    {
                        try
                        {
                            inst.Rollback(state);
                        }
                        catch
                        {
                            // Swallow the rollback exception
                            // and let the real cause bubble up.
                        }

                        throw;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.Message);
            }
        }
コード例 #21
0
    static void Main()
    {
        IDictionary mySavedState = new Hashtable();

        Console.WriteLine("");

        try
        {
// <Snippet2>
            // Create an object of the 'AssemblyInstaller' class.
            AssemblyInstaller myAssemblyInstaller = new AssemblyInstaller();

            // Set the path property of the AssemblyInstaller object.
            myAssemblyInstaller.Path = "MyAssembly_Rollback.exe";
// </Snippet2>

// <Snippet3>
            // Set the logfile name in the commandline argument array.
            string[] commandLineOptions = new string[1] {
                "/LogFile=example.log"
            };
            myAssemblyInstaller.CommandLine = commandLineOptions;
// </Snippet3>

            // Set the 'UseNewContext' property to true.
            myAssemblyInstaller.UseNewContext = true;

            // Install the 'MyAssembly_Rollback' assembly.
            myAssemblyInstaller.Install(mySavedState);

// <Snippet1>
            // 'Rollback' the installation process.
            myAssemblyInstaller.Rollback(mySavedState);
// </Snippet1>
        }
        catch (ArgumentException)
        {
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
        }
    }
コード例 #22
0
 public static bool Install(bool undo, string[] args)
 {
     try
     {
         using (var inst = new AssemblyInstaller(typeof(Program).Assembly, args))
         {
             inst.AfterInstall += OnAfterInstall;
             IDictionary state = new Hashtable();
             inst.UseNewContext = true;
             try
             {
                 if (undo)
                 {
                     inst.Uninstall(state);
                 }
                 else
                 {
                     inst.Install(state);
                     inst.Commit(state);
                 }
             }
             catch
             {
                 try
                 {
                     inst.Rollback(state);
                 }
                 catch
                 {
                     return(false);
                 }
                 throw;
             }
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
         return(false);
     }
     return(true);
 }
コード例 #23
0
        public void OnAction(Hashtable parameters)
        {
            ArrayList arrayList = new ArrayList();

            arrayList.Add("/LogToConsole=false");
            StringBuilder stringBuilder = new StringBuilder();

            foreach (DictionaryEntry dictionaryEntry in parameters)
            {
                if (stringBuilder.Length > 0)
                {
                    stringBuilder.Append(" ");
                }
                stringBuilder.Append(dictionaryEntry.Key);
                stringBuilder.Append("=");
                stringBuilder.Append(dictionaryEntry.Value);
            }
            arrayList.Add("commandline=" + stringBuilder.ToString());
            string[]          commandLine       = (string[])arrayList.ToArray(typeof(string));
            AssemblyInstaller assemblyInstaller = new AssemblyInstaller(Assembly.GetExecutingAssembly(), commandLine);
            Hashtable         hashtable         = new Hashtable();

            if (GameServerService.GetDOLService() != null)
            {
                Console.WriteLine("DOL service is already installed!");
                return;
            }
            Console.WriteLine("Installing Road as system service...");
            try
            {
                assemblyInstaller.Install(hashtable);
                assemblyInstaller.Commit(hashtable);
            }
            catch (Exception ex)
            {
                assemblyInstaller.Rollback(hashtable);
                Console.WriteLine("Error installing as system service");
                Console.WriteLine(ex.Message);
                return;
            }
            Console.WriteLine("Finished!");
        }
コード例 #24
0
ファイル: MasterServerService.cs プロジェクト: saiboat/XMPMS
        /// <summary>
        /// Attempt to install the service
        /// </summary>
        public static void InstallService()
        {
            Console.WriteLine("Attempting to install service '{0}'...", ShortServiceName);

            if (State != ServiceState.NotInstalled)
            {
                Console.WriteLine("Service '{0}' is already installed", ShortServiceName);
                return;
            }

            try
            {
                Console.WriteLine("Service '{0}' was not found. Creating assembly installer...", ShortServiceName);

                IDictionary       savedState = new Hashtable();
                AssemblyInstaller installer  = new AssemblyInstaller(Assembly.GetExecutingAssembly().Location, new string[] { });
                installer.UseNewContext = true;

                try
                {
                    Console.WriteLine("Installing service '{0}'...", ShortServiceName);
                    Console.ForegroundColor = ConsoleColor.Magenta;
                    installer.Install(savedState);
                    Console.ResetColor();
                    Console.WriteLine("Committing changes...", ShortServiceName);
                    Console.ForegroundColor = ConsoleColor.Magenta;
                    installer.Commit(savedState);
                    Console.ResetColor();
                    Console.WriteLine("Service '{0}' was sucessfully installed", ShortServiceName);
                }
                catch (Exception ex)
                {
                    Console.ResetColor();
                    installer.Rollback(savedState);
                    Console.WriteLine("Service '{0}' could not be installed\n{1}", ShortServiceName, ex.Message);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Service '{0}' could not be installed\n{1}", ShortServiceName, ex.Message);
            }
        }
コード例 #25
0
        /// <summary>
        /// Uninstalls the MFC windows service.
        /// </summary>
        public static void UninstallService()
        {
            string[] args = new string[1];
            args[0] = "";
            AssemblyInstaller installer = new AssemblyInstaller(typeof(Program).Assembly, args);

            IDictionary state = new Hashtable();

            installer.UseNewContext = true;

            try
            {
                installer.Uninstall(state);
            }
            catch (Exception e)
            {
                installer.Rollback(state);
                logger.ErrorMethod("UninstallService exception", e);
            }
        }
コード例 #26
0
 private static bool Install(bool isUninstall, string[] args)
 {
     try
     {
         log.DebugFormat(isUninstall ? "Uninstalling" : "Installing");
         using (AssemblyInstaller inst = new AssemblyInstaller(typeof(Service.ServiceInstaller).Assembly, args))
         {
             IDictionary state = new Hashtable();
             inst.UseNewContext = true;
             try
             {
                 if (isUninstall)
                 {
                     inst.Uninstall(state);
                 }
                 else
                 {
                     inst.Install(state);
                     inst.Commit(state);
                 }
                 return(true);
             }
             catch (Exception ex)
             {
                 try
                 {
                     inst.Rollback(state);
                 }
                 catch { }
                 log.Debug(ex.Message);
                 throw;
             }
         }
     }
     catch (Exception ex)
     {
         log.Fatal(ex.Message);
         throw ex;
     }
     //return false;
 }
コード例 #27
0
 static void Install(string[] args, bool installIt = true)
 {
     try
     {
         Console.WriteLine("");   //just a CR
         using (AssemblyInstaller installSvc = new AssemblyInstaller(typeof(Program).Assembly, args))
         {
             IDictionary state = new Hashtable();
             installSvc.UseNewContext = true;
             try
             {
                 if (installIt)
                 {
                     installSvc.Install(state);
                     installSvc.Commit(state);
                     Console.WriteLine(ConfigurationManager.AppSettings["ServiceAfterInstallMsg"]);
                 }
                 else
                 {
                     installSvc.Uninstall(state);
                 }
             }
             catch
             {
                 try
                 {
                     installSvc.Rollback(state);
                 }
                 catch (Exception e)
                 {
                     log.ErrorFormat("Error during {0}Install: {1}", (installIt ? "" : "un-"), e.Message);
                 }
                 throw;
             }
         }
     }
     catch (Exception ex)
     {
         Console.Error.WriteLine(ex.Message);
     }
 }
 /// <summary>
 /// Uninstall the service
 /// </summary>
 public static void Uninstall()
 {
     using (AssemblyInstaller inst = new AssemblyInstaller(typeof(Program).Assembly, null))
     {
         IDictionary state = new Hashtable();
         inst.UseNewContext = true;
         try
         {
             inst.Uninstall(state);
         }
         catch
         {
             try
             {
                 inst.Rollback(state);
             }
             catch { }
             throw;
         }
     }
 }
コード例 #29
0
 private static void InstallService()
 {
     if (IsServiceInstalled)
     {
         return;
     }
     using (AssemblyInstaller installer = Installer)
     {
         IDictionary state = new Hashtable();
         try
         {
             installer.Install(state);
             installer.Commit(state);
         }
         catch
         {
             installer.Rollback(state);
             throw;
         }
     }
 }
コード例 #30
0
        private void BtnInstall_Click(object sender, EventArgs e)
        {
            var savedState = new Hashtable();

            try
            {
                if (this.alreadyInstalled)
                {
                    this.assemblyInstaller.Uninstall(savedState);
                    MessageBox.Show("Successfully uninstalled", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    this.assemblyInstaller.Install(savedState);
                    this.assemblyInstaller.Commit(savedState);
                    MessageBox.Show("Successfully installed", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to install. Original error message:\r\n\r\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                try
                {
                    assemblyInstaller.Rollback(savedState);
                }
                catch { }
            }
            finally
            {
                if (!Runner.Configuration.KeepDialogOpenWhenDone)
                {
                    Application.Exit();
                }
                else
                {
                    this.RefreshInstallState();
                }
            }
        }
コード例 #31
0
ファイル: versaplexd-svc.cs プロジェクト: apenwarr/versaplex
    static void Install()
    {
	// We might already be installed, so uninstall first.  But we might
	// *not* be installed, which is an error, so ignore it.
	try { Uninstall(); } catch { }
	
	using (var inst 
	       = new AssemblyInstaller(typeof(VersaService).Assembly,
				       new string[] { "/logfile" }))
	{
	    inst.UseNewContext = true;

	    IDictionary state = new Hashtable();
	    try
	    {
		inst.Install(state);
		inst.Commit(state);
	    }
	    catch
	    {
		try { inst.Rollback(state); } catch { }
		throw;
	    }
	}
	
	new ServiceController(VersaServiceInstaller.servname).Start();
    }