コード例 #1
0
 /// <summary>
 /// 卸载服务
 /// </summary>
 /// <param name="serviceFilePath"></param>
 private void UninstallService(string serviceFilePath)
 {
     using (AssemblyInstaller installer = new AssemblyInstaller())
     {
         installer.UseNewContext = true;
         installer.Path          = serviceFilePath;
         installer.Uninstall(null);
     }
 }
コード例 #2
0
        /// <summary>
        /// 卸载Windows服务
        /// </summary>
        /// <param name="filepath">程序文件路径</param>
        private static void UnInstallmyService(string filepath)
        {
            var AssemblyInstaller1 = new AssemblyInstaller();

            AssemblyInstaller1.UseNewContext = true;
            AssemblyInstaller1.Path          = filepath;
            AssemblyInstaller1.Uninstall(null);
            AssemblyInstaller1.Dispose();
        }
コード例 #3
0
ファイル: ServiceHelper.cs プロジェクト: luqinlive/vehicle
        /// <summary>
        ///     卸载Windows服务
        /// </summary>
        /// <param name="filepath">程序文件路径</param>
        public static void UnInstallService(string filepath)
        {
            var installer = new AssemblyInstaller();

            installer.UseNewContext = true;
            installer.Path          = filepath;
            installer.Uninstall(null);
            installer.Dispose();
        }
コード例 #4
0
 private static void UnistallService(string path)
 {
     using (AssemblyInstaller installer = new AssemblyInstaller())
     {
         installer.UseNewContext = true;
         installer.Path          = path;
         installer.Uninstall(null);
     }
 }
コード例 #5
0
ファイル: ServiceAPI.cs プロジェクト: angleC/AutoUpdate
        /// <summary>
        /// 卸载Windows服务
        /// </summary>
        /// <param name="serviceFilePath">程序文件路径</param>
        internal static void UnInstallService(string serviceFilePath)
        {
            AssemblyInstaller assemblyInstaller = new AssemblyInstaller();

            assemblyInstaller.UseNewContext = true;
            assemblyInstaller.Path          = serviceFilePath;
            assemblyInstaller.Uninstall(null);
            assemblyInstaller.Dispose();
        }
コード例 #6
0
        public void Desinstala(Entidades.Servico servico)
        {
            var installer = new AssemblyInstaller(servico.Caminho, new[] { "" })
            {
                UseNewContext = true
            };

            installer.Uninstall(null);
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: omgtehlion/tools
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            if (args.Length > 0)
            {
                switch (args[0])
                {
                case "-c":
                    Log = Console.WriteLine;
                    var svc = new Service();
                    svc.TestRun(args.Skip(1).ToArray());
                    Console.WriteLine("Running service...");
                    Console.WriteLine("Press any key to exit.");
                    Console.ReadKey();
                    svc.Stop();
                    break;

                case "-i":
                case "-u":
                    var ins = new AssemblyInstaller(typeof(Program).Assembly.Location, new string[0])
                    {
                        UseNewContext = true
                    };
                    if (args[0] == "-i")
                    {
                        ins.Install(null);
                    }
                    else
                    {
                        ins.Uninstall(null);
                    }

                    ins.Commit(null);
                    break;

                case "-s":
                    new ServiceController(PublicName).Start();
                    break;

                default:
                    Console.Write(@"Unknown switch. Use one of these:
-c      Console: use for test run
-i      Install service
-u      Uninstall service
-s      Start service
");
                    break;
                }
            }
            else
            {
                Log = LogToFile;
                RotateLog();
                ServiceBase.Run(new Service());
            }
        }
コード例 #8
0
ファイル: Form1.cs プロジェクト: batuZ/AM_Node_Controller
 /// <summary>
 /// 卸载服务
 /// </summary>
 private void UninstallService()
 {
     using (AssemblyInstaller installer = new AssemblyInstaller())
     {
         installer.UseNewContext = true;
         installer.Path          = serviceFilePath;
         installer.Uninstall(null);
         MessageBox.Show("服务程序已卸载!");
     }
 }
コード例 #9
0
ファイル: ServiceHelper.cs プロジェクト: zonelim/MasterChief
 /// <summary>
 ///     卸载服务
 /// </summary>
 /// <param name="serviceFilePath">服务路径</param>
 public static void Uninstall(string serviceFilePath)
 {
     ValidateOperator.Begin().CheckFileExists(serviceFilePath);
     using (var installer = new AssemblyInstaller())
     {
         installer.UseNewContext = true;
         installer.Path          = serviceFilePath;
         installer.Uninstall(null);
     }
 }
コード例 #10
0
ファイル: Installer1.cs プロジェクト: zzz1985xxxwl/bjl_hrmis
        private static void UnInstallService(string serverDir)
        {
            //UnInstall Service
            AssemblyInstaller myAssemblyInstaller = new AssemblyInstaller();

            myAssemblyInstaller.UseNewContext = true;
            myAssemblyInstaller.Path          = serverDir;
            myAssemblyInstaller.Uninstall(null);
            myAssemblyInstaller.Dispose();
        }
コード例 #11
0
ファイル: Form1.cs プロジェクト: pangroom/windowservice
        //卸载服务
        private void UninstallService(string serviceName)
        {
            using (AssemblyInstaller installer = new AssemblyInstaller())
            {
                installer.UseNewContext = true;
                installer.Path          = serviceFilePath;
                installer.Uninstall(null);
            }

            //throw new NotImplementedException();
        }
コード例 #12
0
 /// <summary>
 /// 卸载windows服务
 /// </summary>
 /// <param name="filepath">获取或设置要安装的程序集的路径。</param>
 public static void UnInstallService(String serviceName, string filepath)
 {
     if (ServiceIsExisted(serviceName))
     {
         AssemblyInstaller myAssemblyInstaller = new AssemblyInstaller();
         myAssemblyInstaller.UseNewContext = true;
         myAssemblyInstaller.Path          = filepath;
         myAssemblyInstaller.Uninstall(null);
         myAssemblyInstaller.Dispose();
     }
 }
コード例 #13
0
 //卸载服务
 private void UninstallService(string serviceFilePath)
 {
     using (AssemblyInstaller installer = new AssemblyInstaller())
     {
         installer.UseNewContext = true;
         installer.Path          = serviceFilePath;
         installer.Uninstall(null);
     }
     this.serviceLog.Items.Clear();
     this.serviceLog.Items.Add($"{DateTime.Now}:卸载成功!");
 }
コード例 #14
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);
            }
        }
コード例 #15
0
 /// <summary>
 /// 移除服务
 /// </summary>
 /// <returns>移除状态</returns>
 public IDictionary RemoveService()
 {
     using (AssemblyInstaller assemblyInstaller = new AssemblyInstaller())
     {
         assemblyInstaller.UseNewContext = true;
         assemblyInstaller.Path          = _mspath;
         IDictionary savedstate = new Hashtable();
         assemblyInstaller.Uninstall(savedstate);
         return(savedstate);
     }
 }
コード例 #16
0
 /// <summary>
 /// 卸载服务
 /// </summary>
 /// <param name="filepath"></param>
 /// <param name="serviceName"></param>
 public static void UnInstallService(String filepath, String serviceName)
 {
     if (ServiceExist(serviceName))
     {
         AssemblyInstaller ass = new AssemblyInstaller();
         ass.UseNewContext = true;
         ass.Path          = filepath;
         ass.Uninstall(null);
         ass.Dispose();
     }
 }
コード例 #17
0
ファイル: MachineNode.cs プロジェクト: yuexiaoyun/cloudb
        private static void Uninstall()
        {
            string            logFile   = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "uninstall.log");
            InstallContext    context   = new InstallContext(logFile, new string[] { String.Format("/logfile={0}", logFile) });
            AssemblyInstaller installer = new AssemblyInstaller(typeof(MachineNodeService).Assembly,
                                                                new string[] { String.Format("/logfile={0}", logFile) });

            installer.Context       = context;
            installer.UseNewContext = false;
            installer.Uninstall(null);
            installer.Commit(null);
        }
コード例 #18
0
 internal static void UninstallService()
 {
     if (!IsInstalled())
     {
         return;
     }
     using (AssemblyInstaller installer = GetInstaller())
     {
         IDictionary state = new Hashtable();
         installer.Uninstall(state);
     }
 }
コード例 #19
0
        /// <summary>
        /// Remove um serviço do windows do registro
        /// </summary>
        public static void UninstallService(String fileName)
        {
            Directory.SetCurrentDirectory(Path.GetDirectoryName(fileName));
            String serviceName = Path.GetFileNameWithoutExtension(fileName);

            String[] arguments = new string[] { "/LogFile=" + serviceName + "_Install.log" };

            AssemblyInstaller installer = new AssemblyInstaller(fileName, arguments);

            installer.UseNewContext = true;
            installer.Uninstall(null);
        }
コード例 #20
0
 /// <summary>
 /// 卸载
 /// </summary>
 public void UnInstall()
 {
     if (Exist())
     {
         var stateSaver = new Hashtable();
         using (var myAssemblyInstaller = new AssemblyInstaller()) {
             myAssemblyInstaller.UseNewContext = true;
             myAssemblyInstaller.Path          = Path;
             myAssemblyInstaller.Uninstall(stateSaver);
             myAssemblyInstaller.Commit(stateSaver);
         }
     }
 }
コード例 #21
0
        public static void Uninstall(string name)
        {
            DefaultName = name;
            string[] commandLineOptions = new string[] { "/ShowCallStack", "/LogFile=uninstall.log" };

            using (AssemblyInstaller installer = new AssemblyInstaller(Application.ExecutablePath, commandLineOptions))
            {
                installer.UseNewContext = true;

                IDictionary state = new Hashtable();
                installer.Uninstall(state);
            }
        }
コード例 #22
0
        public void UnInstallService(string exeFileName)
        {
            if (!File.Exists(exeFileName))
            {
                return;
            }

            AssemblyInstaller installer = new AssemblyInstaller(exeFileName, null);

            installer.UseNewContext = true;
            installer.Uninstall(null);
            installer.Dispose();
        }
コード例 #23
0
 public override void Execute(object parameter)
 {
     using (
         AssemblyInstaller installer = new AssemblyInstaller
     {
         Path = Path,
         UseNewContext = true
     }
         )
     {
         installer.Uninstall(null);
     }
 }
コード例 #24
0
        public void Uninstall(bool cleanup)
        {
            if (!IsInstalled())
            {
                return;
            }

            Stop();
            using (AssemblyInstaller installer = GetInstaller())
            {
                IDictionary state = new Hashtable();
                installer.Uninstall(state);
            }
        }
コード例 #25
0
        public static void UninstallService(string filename = null)
        {
            Console.WriteLine("Uninstalling service...");
            string[] commandLine = new string[0];
            //commandLine[0] = "/u";
            IDictionary savedState = new Hashtable();

            AssemblyInstaller installer = new AssemblyInstaller(GetServiceFileName(), commandLine);

            installer.Uninstall(savedState);
            //installer.Commit(savedState);
            Console.WriteLine("Complete.");
            LogWrapper.Log(MessageType.MESSAGE_DEBUG, "Деинсталляция прошла успешно");
        }
コード例 #26
0
        public void UninstallService()
        {
            using (AssemblyInstaller installer = new AssemblyInstaller(Path.Combine(Utils.GetApplicationPath(), Utils.GetExecutableName()), null)) {
                installer.UseNewContext = true;
                Hashtable table = new Hashtable();

                try {
                    installer.Uninstall(table);
                }
                catch (Exception ex) {
                    throw new InstallException(String.Format("Uninstall failed, maybe not all parts are removed: {0}", ex.Message), ex);
                }
            }
        }
コード例 #27
0
ファイル: FanSc.cs プロジェクト: syatanic/fantom
        private void DoUninstall()
        {
            List <string> installerArgs = new List <string>();

            installerArgs.Add("/LogToConsole=true");
            installerArgs.Add("/ServiceName=" + ServiceName);

            IDictionary       state     = new Hashtable();
            string            exe       = System.Reflection.Assembly.GetExecutingAssembly().Location;
            AssemblyInstaller installer = new AssemblyInstaller(exe, installerArgs.ToArray());

            installer.UseNewContext = true;
            installer.Uninstall(state);
        }
コード例 #28
0
        private void UninstallService(string exeFilename, string basePath)
        {
            var pathArg            = string.Format("/PATH={0}", basePath);
            var portArg            = string.Format("/PORT={0}", this.Port);
            var displayNameArg     = string.Format("/DisplayName={0}", this.DisplayName);
            var serviceNameArg     = string.Format("/ServiceName={0}", this.ServiceName);
            var commandLineOptions = new string[] { pathArg, portArg, displayNameArg, serviceNameArg };
            var installer          = new AssemblyInstaller(exeFilename, commandLineOptions)
            {
                UseNewContext = true
            };

            installer.Uninstall(null);
        }
コード例 #29
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);
     }
 }
コード例 #30
0
        public static bool Uninstall()
        {
            Tracker.StartServer();

            bool result = true;

            InstallContext context = null;

            try
            {
                using (var inst = new AssemblyInstaller(typeof(ServerLifecycleManager).Assembly, null))
                {
                    context = inst.Context;
                    LogMessage("Uninstalling service " + AppSettings.ServiceName, inst.Context);
                    IDictionary state = new Hashtable();
                    inst.UseNewContext = true;
                    try
                    {
                        inst.Uninstall(state);
                        Tracker.TrackEvent(TrackerEventGroup.Installations, TrackerEventName.Uninstalled);
                    }
                    catch (Exception err)
                    {
                        Tracker.TrackException("WindowsServiceManager", "Uninstall", 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);
        }
コード例 #31
0
ファイル: versaplexd-svc.cs プロジェクト: apenwarr/versaplex
    static void Uninstall()
    {
	using (var inst 
	       = new AssemblyInstaller(typeof(VersaService).Assembly,
				       new string[] { "/logfile" }))
	{
	    inst.UseNewContext = true;
	    inst.Uninstall(new Hashtable());
	}
    }