• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Install.AssemblyInstaller类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



AssemblyInstaller类属于System.Configuration.Install命名空间,在下文中一共展示了AssemblyInstaller类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: UninstallWindowsService

        public static bool UninstallWindowsService()
        {
            StopService();
            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.Uninstall(mySavedState);

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

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


示例3: GetInstaller

 private static AssemblyInstaller GetInstaller()
 {
     AssemblyInstaller installer = new AssemblyInstaller(
         typeof(SetItUpService).Assembly, null);
     installer.UseNewContext = true;
     return installer;
 }
开发者ID:Wryxo,项目名称:bakalarka,代码行数:7,代码来源:Program.cs


示例4: GetInstaller

 /// <summary>
 /// 
 /// </summary>
 /// <param name="assembly"></param>
 /// <returns></returns>
 public static AssemblyInstaller GetInstaller(string serviceName)
 {
     //TODO: THis is not working
     AssemblyInstaller installer = new AssemblyInstaller();
     installer.UseNewContext = true;
     return installer;
 }
开发者ID:navkar,项目名称:BizTalkControlCenter,代码行数:12,代码来源:BCCServiceHelper.cs


示例5: 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


示例6: GetInstaller

 private static AssemblyInstaller GetInstaller()
 {
     AssemblyInstaller installer = new AssemblyInstaller(
         typeof(Program).Assembly, null);
     installer.UseNewContext = true;
     return installer;
 }
开发者ID:robertbreker,项目名称:cloudstack,代码行数:7,代码来源:Program.cs


示例7: ServiceInstaller

        private static bool ServiceInstaller(bool uninstall = false)
        {
            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;

                if (!uninstall)
                {
                    myAssemblyInstaller.Install(mySavedState);
                    // Commit the 'MyAssembly' assembly.
                    myAssemblyInstaller.Commit(mySavedState);
                }
                else
                { myAssemblyInstaller.Uninstall(mySavedState); }
            }
            catch (FileNotFoundException)
            {
                throw;
            }
            catch (Exception)
            { return false; }
            
            return true;
        }
开发者ID:GHLabs,项目名称:SambaPOS-3,代码行数:33,代码来源:ServiceHelper.cs


示例8: InstallService

 /// <summary>
 /// 安装服务。
 /// </summary>
 /// <param name="fileName">文件名称</param>
 /// <param name="args">命令行参数</param>
 public static void InstallService(string fileName, string[] args)
 {
     TransactedInstaller transactedInstaller = new TransactedInstaller();
     AssemblyInstaller assemblyInstaller = new AssemblyInstaller(fileName, args);
     transactedInstaller.Installers.Add(assemblyInstaller);
     transactedInstaller.Install(new System.Collections.Hashtable());
 }
开发者ID:jihadbird,项目名称:firespider,代码行数:12,代码来源:ServiceUtil.cs


示例9: InstallService

 /// <summary>
 /// 安装windows服务
 /// </summary>
 private void InstallService(IDictionary stateSaver, string filepath, string serviceName)
 {
     try
     {
         ServiceController service = new ServiceController(serviceName);
         if (!ServiceIsExisted(serviceName))
         {
             AssemblyInstaller myAssemblyInstaller = new AssemblyInstaller();
             myAssemblyInstaller.UseNewContext = true;
             myAssemblyInstaller.Path = filepath;
             myAssemblyInstaller.Install(stateSaver);
             myAssemblyInstaller.Commit(stateSaver);
             myAssemblyInstaller.Dispose();
             service.Start();
         }
         else
         {
             if (service.Status != ServiceControllerStatus.Running && service.Status != ServiceControllerStatus.StartPending)
                 service.Start();
         }
     }
     catch (Exception ex)
     {
         throw new Exception("InstallServiceError\r\n" + ex.Message);
     }
 }
开发者ID:yonglehou,项目名称:BPMSV1,代码行数:29,代码来源:ServicesHelper.cs


示例10: Installation

        public Installation() : base() 
        {
            #region Install on MSR.LST.Net.Rtp (a necessary dependency)
            AssemblyInstaller ai = new AssemblyInstaller();
            ai.UseNewContext = true;
            ai.Assembly = Assembly.Load("MSR.LST.Net.Rtp");
            Installers.Add(ai);
            #endregion
            
            #region Install MDShowManager (if it is in the same directory)
            FileInfo fi = new FileInfo(Assembly.GetExecutingAssembly().Location);
            FileInfo[] foundFiles = fi.Directory.GetFiles("MDShowManager.dll");
            if (foundFiles.Length == 1)
            {
                ai = new AssemblyInstaller();
                ai.UseNewContext = true;
                ai.Path = foundFiles[0].FullName;
                Installers.Add(ai);
            }
            #endregion

            #region Install Pipecleaner Agent Service (if it is in the same directory)
            fi = new FileInfo(Assembly.GetExecutingAssembly().Location);
            foundFiles = fi.Directory.GetFiles("Pipecleaner Agent Service.exe");
            if (foundFiles.Length == 1)
            {
                ai = new AssemblyInstaller();
                ai.UseNewContext = true;
                ai.Path = foundFiles[0].FullName;
                Installers.Add(ai);
            }
            #endregion
        }
开发者ID:psyCHOder,项目名称:conferencexp,代码行数:33,代码来源:Installation.cs


示例11: 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


示例12: 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


示例13: btnInstall_Click

 /// <summary>
 /// 安装服务
 /// </summary>
 private void btnInstall_Click(object sender, EventArgs e)
 {
     if (!Vaild())
     {
         return;
     }
     try
     {
         string[] cmdline = { };
         string serviceFileName = txtPath.Text.Trim();
         string serviceName = GetServiceName(serviceFileName);
         if (string.IsNullOrEmpty(serviceName))
         {
             txtTip.Text = "指定文件不是Windows服务!";
             return;
         }
         if (ServiceIsExisted(serviceName))
         {
             txtTip.Text = "要安装的服务已经存在!";
             return;
         }
         TransactedInstaller transactedInstaller = new TransactedInstaller();
         AssemblyInstaller assemblyInstaller = new AssemblyInstaller(serviceFileName, cmdline);
         assemblyInstaller.UseNewContext = true;
         transactedInstaller.Installers.Add(assemblyInstaller);
         transactedInstaller.Install(new System.Collections.Hashtable());
         txtTip.Text = "服务安装成功!";
     }
     catch (Exception ex)
     {
         txtTip.Text = ex.Message;
     }
 }
开发者ID:Zorbam,项目名称:TaskManager,代码行数:36,代码来源:FrmMain.cs


示例14: GetInstaller

 private static AssemblyInstaller GetInstaller(System.Reflection.Assembly assem)
 {
     AssemblyInstaller installer = new AssemblyInstaller(
         assem, null);
     installer.UseNewContext = true;
     return installer;
 }
开发者ID:erynet,项目名称:IMS,代码行数:7,代码来源:ServiceControl.cs


示例15: Uninstall

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

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

                        try
                        {
                            installer.Rollback(state);
                        }
                        catch (Exception exception)
                        {
                            Console.WriteLine(exception.ToString());
                        }
                    }
                }
            }
            catch (Exception exception)
            {

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


示例16: 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


示例17: Installation

 public Installation() : base() 
 {
     // - Add the installer for MSR.LST.Net.Rtp to the list
     AssemblyInstaller rtpInstall = new AssemblyInstaller();
     rtpInstall.Assembly = Assembly.Load("MSR.LST.Net.Rtp");
     Installers.Add(rtpInstall);
 }
开发者ID:abhishek-kumar,项目名称:AIGA,代码行数:7,代码来源:Installer.cs


示例18: Main

        private static void Main(string[] args)
        {
            AppDomain.CurrentDomain.SetupInformation.PrivateBinPath = "." + Path.DirectorySeparatorChar + "lib";

            Thread.CurrentThread.Name = "MAIN";

            AssemblyInstaller installer = new AssemblyInstaller(Assembly.GetExecutingAssembly(), null);

            Hashtable rollback = new Hashtable();

            try
            {
                //installer.Install(rollback);
                //installer.Commit(rollback);
                ////installer.Uninstall(rollback);
            }
            catch (Exception ex)
            {
                //installer.Rollback(rollback);
                Console.WriteLine("Error installing as system service");
                Console.WriteLine(ex.Message);
                //Console.ReadKey();
            }
            Console.ReadKey();
        }
开发者ID:W8023Y2014,项目名称:jsion,代码行数:25,代码来源:Program.cs


示例19: TryRollback

        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);
            }

        }
开发者ID:vjohnson01,项目名称:Tools,代码行数:9,代码来源:InstallUtil.cs


示例20: 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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Install.InstallContext类代码示例发布时间:2022-05-26
下一篇:
C# Configuration.XmlUtilWriter类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap