当前位置: 首页>>代码示例>>C#>>正文


C# AssemblyInstaller.Commit方法代码示例

本文整理汇总了C#中System.Configuration.Install.AssemblyInstaller.Commit方法的典型用法代码示例。如果您正苦于以下问题:C# AssemblyInstaller.Commit方法的具体用法?C# AssemblyInstaller.Commit怎么用?C# AssemblyInstaller.Commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Configuration.Install.AssemblyInstaller的用法示例。


在下文中一共展示了AssemblyInstaller.Commit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InstallService

        public void InstallService(string user, string pass) {
            using (AssemblyInstaller installer = new AssemblyInstaller(Path.Combine(Utils.GetApplicationPath(), Utils.GetExecutableName()), null)) {
                installer.UseNewContext = true;
                Hashtable savedState = new Hashtable();

                UserPassCombination c = new UserPassCombination();
                c.User = user;
                c.Pass = pass;
                _userPassCombination = c;

                installer.BeforeInstall += new InstallEventHandler(installer_BeforeInstall);

                //Rollback has to be called by user code. According msdn-doc for AssemblyInstaller.Install() is probably wrong.
                try {
                    installer.Install(savedState);
                    installer.Commit(savedState);
                }
                catch (Exception ex) {
                    installer.Rollback(savedState);
                    throw new InstallException(String.Format("Install failed: {0}", ex.Message), ex);
                }

                installer.BeforeInstall -= installer_BeforeInstall;
            }
        }
开发者ID:shabbirh,项目名称:virtualboxservice,代码行数:25,代码来源:ElevatedService.cs

示例2: InstallWindowsService

        public static bool InstallWindowsService()
        {
            IDictionary mySavedState = new Hashtable();           

            try
            {
                // Set the commandline argument array for 'logfile'.
                string[] commandLineOptions = new string[1] { string.Format("/LogFile={0}", _logFile) };

                // Create an object of the 'AssemblyInstaller' class.
                AssemblyInstaller myAssemblyInstaller = new
                AssemblyInstaller(_installAssembly, commandLineOptions);
                

                myAssemblyInstaller.UseNewContext = true;

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

                // Commit the 'MyAssembly' assembly.
                myAssemblyInstaller.Commit(mySavedState);
            }
            catch (Exception e)
            { return false; }

            StartService();
            return true;
        }
开发者ID:GHLabs,项目名称:SambaPOS-3,代码行数:28,代码来源:ServiceHelper.cs

示例3: Install

        public static void Install(string[] args)
        {
            try
            {
                using (var installer = new AssemblyInstaller(typeof(InstallationManager).Assembly, args))
                {
                    IDictionary state = new Hashtable();

                    // Install the service
                    installer.UseNewContext = true;
                    try
                    {
                        installer.Install(state);
                        installer.Commit(state);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);

                        try
                        {
                            installer.Rollback(state);
                        }
                        catch (Exception exception)
                        {
                            Console.WriteLine(exception.Message);
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine("Failed to install service. Error: " + exception.Message);
            }
        }
开发者ID:hagenson,项目名称:SysLogSharp,代码行数:35,代码来源:InstallationManager.cs

示例4: Install

        private void Install(AssemblyInstaller installer, IDictionary state, bool undo)
        {

            try
            {
                if (undo)
                {
                    _log.Write(LogLevel.Info, "Uninstalling {0}...", StringConstants.ServiceName);
                    installer.Uninstall(state);
                    _log.Write(LogLevel.Info, "{0} has been successfully removed from the system.", StringConstants.ServiceName);
                }
                else
                {
                    _log.Write(LogLevel.Info, "Installing {0}...", StringConstants.ServiceName);
                    installer.Install(state);

                    _log.Write(LogLevel.Info, "Commiting changes...");
                    installer.Commit(state);

                    _log.Write(LogLevel.Info, "Install succeeded.");
                }
            }
            catch (Exception ex)
            {
                _log.Write(LogLevel.Error, "An error occured during {1}. {0}", ex, undo?"uninstall" : "install");
                _log.Write(LogLevel.Info, "Trying to roll back...");
                TryRollback(installer, state);
            }
        }
开发者ID:vjohnson01,项目名称:Tools,代码行数:29,代码来源:InstallUtil.cs

示例5: Install

 static void Install(bool undo, string[] args)
 {
     try
     {
         Console.WriteLine(undo ? "Uninstalling" : "Installing");
         using (AssemblyInstaller inst = new AssemblyInstaller(typeof(WinSvc).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 { }
                 throw;
             }
         }
         Console.WriteLine("Done");
     }
     catch (Exception ex)
     {
         Console.Error.WriteLine(ex.Message);
     }
 }
开发者ID:rmbolger,项目名称:RemoteBootPicker,代码行数:32,代码来源:EntryPoint.cs

示例6: InstallService

 /// <summary>
 /// 安装服务:
 /// </summary>
 /// <param name="filepath"></param>
 public void InstallService(string filepath)
 {
     try
     {
         string serviceName = GetServiceName(filepath);
         ServiceController service = new ServiceController(serviceName);
         if (!ServiceIsExisted(serviceName))
         {
             //Install Service
             AssemblyInstaller myAssemblyInstaller = new AssemblyInstaller() { UseNewContext = true, Path = filepath };
             myAssemblyInstaller.Install(new Hashtable());
             myAssemblyInstaller.Commit(new Hashtable());
             myAssemblyInstaller.Dispose();
             //--Start Service
             service.Start();
         }
         else
         {
             if (service.Status != ServiceControllerStatus.Running && service.Status != ServiceControllerStatus.StartPending)
             {
                 service.Start();
             }
         }
     }
     catch (Exception ex)
     {
         throw new Exception("installServiceError/n" + ex.Message);
     }
 }
开发者ID:yangdaichun,项目名称:ZHXY.ZSXT,代码行数:33,代码来源:ManageService.cs

示例7: InstallTheService

 public void InstallTheService()
 {
     try
     {
         IDictionary state = new Hashtable();
         using (AssemblyInstaller installer = new AssemblyInstaller(InstallersAssembly, Args))
         {
             installer.UseNewContext = true;
             try
             {
                 installer.Install(state);
                 installer.Commit(state);
                 InternalTrace("Installed the service");
             }
             catch (Exception installException)
             {
                 try
                 {
                     installer.Rollback(state);
                     InternalTrace("Rolledback the service installation because:" + installException.ToString());
                 }
                 catch { }
                 throw;
             }
         }
     }
     catch (Exception exception)
     {
         InternalTrace("Failed to install the service " + exception.ToString());
     }
 }
开发者ID:MecuSorin,项目名称:Configurari,代码行数:31,代码来源:CommandLineManager.cs

示例8: InstallService

 /// <summary>
 /// 安装Windows服务
 /// </summary>
 /// <param name="stateSaver">状态集合</param>
 /// <param name="filepath">程序文件路径</param>
 public static void InstallService(IDictionary stateSaver, String filepath)
 {
     AssemblyInstaller AssemblyInstaller1 = new AssemblyInstaller();
     AssemblyInstaller1.UseNewContext = true;
     AssemblyInstaller1.Path = filepath;
     AssemblyInstaller1.Install(stateSaver);
     AssemblyInstaller1.Commit(stateSaver);
     AssemblyInstaller1.Dispose();
 }
开发者ID:gavincode,项目名称:ExcelTool,代码行数:14,代码来源:ServiceInstaller.cs

示例9: InstallAssembly

        /// <summary>
        /// Install the service that is contained in specified assembly.
        /// </summary>
        /// <param name="pathToAssembly">Path to service assembly.</param>
        /// <param name="commandLineArguments">Parameters, that are passed to assembly.</param>
        public static void InstallAssembly(string pathToAssembly, string[] commandLineArguments)
        {
            List<string> argList = new List<string>(commandLineArguments);

            argList.Add(string.Format("/LogFile={0}_install.log",
                                        Path.GetFileNameWithoutExtension(pathToAssembly)));
            using (AssemblyInstaller installer = new AssemblyInstaller(pathToAssembly, argList.ToArray())) {
                var state = new Hashtable();
                installer.Install(state);
                installer.Commit(state);
            }
        }
开发者ID:alexsharoff,项目名称:windows-service-toolkit,代码行数:17,代码来源:InstallUtilities.cs

示例10: InstallService

        /// <summary>
        /// Acrescenta um serviço do windows no registro
        /// </summary>
        public static void InstallService(String fileName)
        {
            Directory.SetCurrentDirectory(Path.GetDirectoryName(fileName));
            String serviceName = Path.GetFileNameWithoutExtension(fileName);
            String[] arguments = new string[] { "/LogFile=" + serviceName + "_Install.log" };
            IDictionary state = new Hashtable();

            AssemblyInstaller installer = new AssemblyInstaller(fileName, arguments);
            installer.UseNewContext = true;
            installer.Install(state);
            installer.Commit(state);
        }
开发者ID:renatosans,项目名称:contratos,代码行数:15,代码来源:ServiceHandler.cs

示例11: Install

        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);
            }
        }
开发者ID:akshaynm87,项目名称:FamServer,代码行数:51,代码来源:Program.cs

示例12: InstallService

        public static void InstallService()
        {
            string exePath = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
            string strDir = System.IO.Path.GetDirectoryName(exePath);
            string filepath = strDir + "\\MPlayerWWService.exe";

            IDictionary mSavedState = new Hashtable();
            AssemblyInstaller myAssemblyInstaller = new AssemblyInstaller();
            myAssemblyInstaller.UseNewContext = true;
            myAssemblyInstaller.Path = filepath;
            myAssemblyInstaller.Install(mSavedState);
            myAssemblyInstaller.Commit(mSavedState);
            myAssemblyInstaller.Dispose();
        }
开发者ID:william0wang,项目名称:meditor,代码行数:14,代码来源:Program.cs

示例13: Install

        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;
        }
开发者ID:Robin--,项目名称:Warewolf,代码行数:49,代码来源:WindowsServiceManager.cs

示例14: InstallmyService

 /// <summary>
 /// 安装Windows服务
 /// </summary>
 /// <param name="stateSaver">集合,当传递给 Install 方法时,stateSaver 参数指定的 IDictionary 应为空。</param>
 /// <param name="filepath">程序文件路径</param>
 public static void InstallmyService(IDictionary stateSaver, string filepath)
 {
     try
     {
         AssemblyInstaller AssemblyInstaller1 = new AssemblyInstaller();
         AssemblyInstaller1.UseNewContext = true;
         AssemblyInstaller1.Path = filepath;
         stateSaver.Clear();
         AssemblyInstaller1.Install(stateSaver);
         AssemblyInstaller1.Commit(stateSaver);
         AssemblyInstaller1.Dispose();
     }
     catch (Exception exp)
     {
         MessageBox.Show(exp.Message.ToString());
     }
 }
开发者ID:fuwei199006,项目名称:lottery,代码行数:22,代码来源:Windows.cs

示例15: Install

 // 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;
         }
     }
 }
开发者ID:xkjyeah,项目名称:openvpnserv2,代码行数:19,代码来源:ProjectInstaller.cs


注:本文中的System.Configuration.Install.AssemblyInstaller.Commit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。