Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
        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;
        }
Ejemplo n.º 3
0
 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);
     }
 }
Ejemplo n.º 4
0
        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);
            }
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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();
     }
 }
Ejemplo n.º 7
0
        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);
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// 卸载Windows服务
 /// </summary>
 /// <param name="filepath">程序文件路径</param>
 public static void UnInstallmyService(IDictionary stateSaver,string filepath)
 {
     try
     {
         AssemblyInstaller AssemblyInstaller1 = new AssemblyInstaller();
         AssemblyInstaller1.UseNewContext = true;
         AssemblyInstaller1.Path = filepath;
         AssemblyInstaller1.Uninstall(stateSaver);
         AssemblyInstaller1.Dispose();
     }
     catch (Exception exp)
     {
         MessageBox.Show(exp.Message.ToString());
     }
 }
Ejemplo n.º 9
0
 public static void Uninstall()
 {
     using (AssemblyInstaller installer =
             new AssemblyInstaller(typeof(OpenVpnService).Assembly, null))
     {
         installer.UseNewContext = true;
         var state = new System.Collections.Hashtable();
         try
         {
             installer.Uninstall(state);
         }
         catch
         {
             throw;
         }
     }
 }
Ejemplo n.º 10
0
 /// <summary>
 /// 卸载windows服务:
 /// </summary>
 /// <param name="filepath"></param>
 public void UnInstallService(string filepath)
 {
     try
     {
         string serviceName = GetServiceName(filepath);
         if (ServiceIsExisted(serviceName))
         {
             //UnInstall Service
             AssemblyInstaller myAssemblyInstaller = new AssemblyInstaller() { UseNewContext = true, Path = filepath };
             myAssemblyInstaller.Uninstall(null);
             myAssemblyInstaller.Dispose();
         }
     }
     catch (Exception ex)
     {
         throw new Exception("unInstallServiceError/n" + ex.Message);
     }
 }
Ejemplo n.º 11
0
        public static string Uninstall(string filePath, string serviceName)
        {
            string msg = string.Empty;

            try
            {
                System.Configuration.Install.AssemblyInstaller myAssemblyInstaller = new System.Configuration.Install.AssemblyInstaller();
                myAssemblyInstaller.UseNewContext = true;
                myAssemblyInstaller.Path          = filePath;
                myAssemblyInstaller.Uninstall(null);
                myAssemblyInstaller.Dispose();
                msg = "卸载服务" + serviceName + "成功!";
            }
            catch (Exception er)
            {
                msg = er.ToString();
            }
            return(msg);
        }
Ejemplo n.º 12
0
        static void Install(bool undo, string[] args)
        {
            try
            {
                Logger.Log(undo ? "Uninstalling ..." : "Installing ... ");
                using (var inst = new AssemblyInstaller(typeof(Program).Assembly, args))
                {
                    var state = new Hashtable();
                    inst.UseNewContext = true;
                    try
                    {
                        if (undo)
                        {
                            inst.Uninstall(state);
                        }
                        else
                        {
                            inst.Install(state);
                            inst.Commit(state);

                            StartService();
                        }
                    }
                    catch (Exception ex)
                    {
                        try
                        {
                            Logger.Log(ex);
                            inst.Rollback(state);
                        }
                        catch { }
                        throw;
                    }
                    inst.Dispose();
                }
                Logger.Log("... finished");
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
            }
        }
        public static bool Install(bool undo, string[] args)
        {
            try
            {
                Console.WriteLine(undo ? "Uninstalling..." : "Installing...");
                using (AssemblyInstaller inst = new AssemblyInstaller(typeof(WakeService).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;
                    }
                }

                return true;
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.Message);
            }

            return false;
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Uninstalls the assembly specified by <see cref="P:assemblyPath" />
        /// </summary>
        /// <param name="assemblyPath">Full path to the assembly to uninstall</param>
        public static void Uninstall(string assemblyPath)
        {
            try
            {
                AssemblyInstaller installer = new AssemblyInstaller(assemblyPath, new String[] { })
                {
                    UseNewContext = true
                };

                installer.Uninstall(null);
                installer.Commit(null);
            }
            catch (FileNotFoundException exception)
            {
                Console.WriteLine("[!] Installer state file not found, uninstalling service without storing the state" + exception.Message);
            }
            catch (Exception exception2)
            {
                Console.WriteLine("[!] Unable to uninstall service: " + exception2.Message);
            }
        }
Ejemplo n.º 15
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;
 }
Ejemplo n.º 16
0
 static void Main(string[] args)
 {
     var notRun = true;
     if (args.Length > 0)
     {
         if (args[0] == "-i" || args[0] == "-I")
         {
             notRun = false;
             var stateServer = new Hashtable();
             var assemblyInstaller = new AssemblyInstaller(typeof(Program).Assembly, null);
             assemblyInstaller.Install(stateServer);
         }
         else if (args[0] == "-u" || args[0] == "-U")
         {
             notRun = false;
             var assemblyInstaller = new AssemblyInstaller(typeof(Program).Assembly, null);
             var stateServer = new Hashtable();
             assemblyInstaller.Uninstall(stateServer);
         }
     }
     if (notRun)
     {
         if (System.Diagnostics.Debugger.IsAttached == true)
         {
             const string userName = "******";
             const string password = "******";
             const string hostName = "10.26.10.150";
             var debugForm = new DebugForm(userName, password, hostName);
             debugForm.ShowDialog();
         }
         else
         {
             string userName = ConfigurationManager.AppSettings["UserName"];
             string password = ConfigurationManager.AppSettings["PassWord"];
             string hostName = ConfigurationManager.AppSettings["HostName"];
             ServiceBase.Run(new SAFTeamCityService(userName, password, hostName));
         }
     }
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="exeFilename">Installer class (not the service class!)</param>
        /// <param name="exception"></param>
        /// <returns></returns>
        public static bool UninstallService(string exeFilename, out Exception exception)
        {
            exception = null;
            string[] commandLineOptions = new string[1] {
                "/LogFile=uninstall.log"
            };

            System.Configuration.Install.AssemblyInstaller installer =
                new System.Configuration.Install.AssemblyInstaller(exeFilename, commandLineOptions);

            try
            {
                installer.UseNewContext = true;
                installer.Uninstall(null);
            }
            catch (Exception ex)
            {
                exception = ex;
                return(false);
            }
            return(true);
        }
Ejemplo n.º 18
0
 public void OnAction(Hashtable parameters)
 {
     System.Configuration.Install.AssemblyInstaller asmInstaller = new AssemblyInstaller(Assembly.GetExecutingAssembly(), new string[1] { "/LogToConsole=false" });
     Hashtable rollback = new Hashtable();
     if (GameServerService.GetDOLService() == null)
     {
         Console.WriteLine("No service named \"DOL\" found!");
         return;
     }
     Console.WriteLine("Uninstalling DOL system service...");
     try
     {
         asmInstaller.Uninstall(rollback);
     }
     catch (Exception e)
     {
         Console.WriteLine("Error uninstalling system service");
         Console.WriteLine(e.Message);
         return;
     }
     Console.WriteLine("Finished!");
 }
Ejemplo n.º 19
0
 /// <summary>
 /// Actually installs/uninstalls this service.
 /// </summary>
 /// <param name="undo"></param>
 /// <param name="args"></param>
 private static void Install(bool undo, string[] args)
 {
     try
     {
         using (AssemblyInstaller installer = new AssemblyInstaller(
             Assembly.GetEntryAssembly(), args))
         {
             IDictionary savedState = new Hashtable();
             installer.UseNewContext = true;
             try
             {
                 if (undo)
                 {
                     installer.Uninstall(savedState);
                 }
                 else
                 {
                     installer.Install(savedState);
                     installer.Commit(savedState);
                 }
             }
             catch
             {
                 try
                 {
                     installer.Rollback(savedState);
                 }
                 catch
                 {
                 }
                 throw;
             }
         }
     }
     catch (Exception exception)
     {
         Console.Error.WriteLine(exception.Message);
     }
 }
Ejemplo n.º 20
0
 private static void InstallService(bool undo, string[] args)
 {
     using (AssemblyInstaller inst = new AssemblyInstaller(Assembly.GetExecutingAssembly(), args)) {
         var 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;
         }
     }
 }
 public static void Install(bool undo, string openvpn)
 {
     try
     {
         using (AssemblyInstaller inst = new AssemblyInstaller(typeof(OpenVPNServiceRunner).Assembly, new String[0]))
         {
             IDictionary state = new Hashtable();
             inst.UseNewContext = true;
             try
             {
                 if (undo)
                 {
                     inst.Uninstall(state);
                 }
                 else
                 {
                     inst.Install(state);
                     inst.Commit(state);
                     SetParameters(openvpn);
                 }
             }
             catch
             {
                 try
                 {
                     inst.Rollback(state);
                 }
                 catch { }
                 throw;
             }
         }
     }
     catch (Exception ex)
     {
         Console.Error.WriteLine(ex.Message);
     }
 }
Ejemplo n.º 22
0
        static void Main(string[] args)
        {
            bool isConsole = false;

            try
            {
                // Get DateTime.ToString() to use a format ot ToString("o") instead of ToString("G").
                CultureInfo culture = (CultureInfo)CultureInfo.CurrentCulture.Clone();
                culture.DateTimeFormat.ShortDatePattern = "yyyy-MM-dd";
                culture.DateTimeFormat.LongTimePattern = "THH:mm:ss.fffffffzzz";
                Thread.CurrentThread.CurrentCulture = culture;

                m_serverStorageType = (AppState.GetConfigSetting(m_storageTypeKey) != null) ? StorageTypesConverter.GetStorageType(AppState.GetConfigSetting(m_storageTypeKey)) : StorageTypes.Unknown;
                m_serverStorageConnStr = AppState.GetConfigSetting(m_connStrKey);
                bool monitorCalls = true;

                if (m_serverStorageType == StorageTypes.Unknown || m_serverStorageConnStr.IsNullOrBlank())
                {
                    throw new ApplicationException("The SIP Application Service cannot start with no persistence settings specified.");
                }

                SIPAllInOneDaemon daemon = null;

                if (args != null && args.Length == 1 && args[0] == "-i")
                {
                    try
                    {
                        using (AssemblyInstaller inst = new AssemblyInstaller(typeof(MainConsole).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;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.Error.WriteLine(ex.Message);
                    }
                }
                else if (args != null && args.Length == 1 && args[0] == "-u")
                {
                    try
                    {
                        using (AssemblyInstaller inst = new AssemblyInstaller(typeof(MainConsole).Assembly, args))
                        {
                            IDictionary state = new Hashtable();
                            inst.UseNewContext = true;
                            try
                            {

                                inst.Uninstall(state);
                            }
                            catch
                            {
                                try
                                {
                                    inst.Rollback(state);
                                }
                                catch { }
                                throw;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.Error.WriteLine(ex.Message);
                    }
                }
                else if (args != null && args.Length == 1 && args[0].StartsWith("-c") || System.Environment.UserInteractive == true)
                {
                    isConsole = true;
                    Console.WriteLine("SIP App Server starting");
                    logger.Debug("SIP App Server Console starting...");

                    string sipSocket = null;
                    string callManagerSvcAddress = null;

                    if (args != null && args.Length > 0)
                    {
                        foreach (string arg in args)
                        {
                            if (arg.StartsWith("-sip:"))
                            {
                                sipSocket = arg.Substring(5);
                            }
                            else if (arg.StartsWith("-cms:"))
                            {
                                callManagerSvcAddress = arg.Substring(5);
                            }
                            else if (arg.StartsWith("-hangupcalls:"))
                            {
                                monitorCalls = Convert.ToBoolean(arg.Substring(13));
                            }
                        }
                    }

                    if (sipSocket.IsNullOrBlank() || callManagerSvcAddress.IsNullOrBlank())
                    {
                        daemon = new SIPAllInOneDaemon(m_serverStorageType, m_serverStorageConnStr);
                    }
                    else
                    {
                        daemon = new SIPAllInOneDaemon(m_serverStorageType, m_serverStorageConnStr, SIPEndPoint.ParseSIPEndPoint(sipSocket), callManagerSvcAddress, monitorCalls);
                    }

                    Thread daemonThread = new Thread(new ThreadStart(daemon.Start));
                    daemonThread.Start();

                    Console.CancelKeyPress += delegate (object sender, ConsoleCancelEventArgs e) {
                        e.Cancel = true;
                        Console.WriteLine("Ctrl-C, clean up and exit...");
                        daemon.Stop();
                        m_proxyUp.Set();
                    };

                    m_proxyUp.WaitOne();
                }
                else
                {
                    logger.Debug("SIP App Server Windows Service Starting...");
                    System.ServiceProcess.ServiceBase[] ServicesToRun;
                    daemon = new SIPAllInOneDaemon(m_serverStorageType, m_serverStorageConnStr);
                    ServicesToRun = new System.ServiceProcess.ServiceBase[] { new Service(daemon) };
                    System.ServiceProcess.ServiceBase.Run(ServicesToRun);
                }
            }
            catch (Exception excp)
            {
                Console.WriteLine("Exception SIP App Server Main. " + excp.Message);

                if (isConsole) {
                    Console.WriteLine("press any key to exit...");
                    Console.ReadLine();
                }
            }
        }
Ejemplo n.º 23
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);
                }
            }
		}
Ejemplo n.º 24
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 { }
         }
     }
 }
Ejemplo n.º 25
0
 /// <summary>
 /// Uninstalls this service
 /// </summary>
 void UninstallThis()
 {
     try {
         using (var i = new AssemblyInstaller(ProgramType.Assembly, null) { UseNewContext = true }) {
             IDictionary s = new Hashtable();
             try {
                 i.Uninstall(s);
             } catch {
                 try {
                     i.Rollback(s);
                 } catch { }
                 throw;
             }
         }
         Console.WriteLine(Messages.Done);
     } catch (Exception x) {
         Console.Error.WriteLine(x.Message);
         ReturnValue = 1;
     }
 }
Ejemplo n.º 26
0
        /// <summary>
        /// Handle installation and uninstallation.
        /// </summary>
        /// <param name="uninstall">Whether we're uninstalling.  False if installing, true if uninstalling</param>
        /// <param name="args">Any service installation arguments.</param>
        public void Install(bool uninstall, string[] args)
        {
            try
            {
                using (AssemblyInstaller installer = new AssemblyInstaller(typeof(Program).Assembly, args))
                {
                    IDictionary state = new Hashtable();
                    installer.UseNewContext = true;
                    try
                    {
                        // Attempt to install or uninstall.
                        if (uninstall)
                            installer.Uninstall(state);
                        else
                        {
                            installer.Install(state);
                            installer.Commit(state);
                        }
                    }
                    catch
                    {
                        // If an error is encountered, attempt to roll back.
                        try
                        {
                            installer.Rollback(state);
                        }
                        catch { }

                        throw;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.Message);
            }
        }
        private void Register(bool undo)
        {
            Log.Debug("Registering Poweshell Plugin");
            var core = Common.ApiPath + @"\Plugins\PowerShell\OSAE.PowerShellProcessor.dll";
            using (var install = new AssemblyInstaller(core, null))
            {

                IDictionary state = new Hashtable();
                install.UseNewContext = true;
                try
                {
                    if (undo)
                        install.Uninstall(state);
                    else
                    {
                        install.Install(state);
                        install.Commit(state);
                    }
                }
                catch
                { install.Rollback(state); }
            }

            if (PluginRegistered())
                Log.Debug("Powershell Plugin successfully registered");
            else
                Log.Debug("Powershell Plugin failed to register");
        }
Ejemplo n.º 28
0
        private async void btnUninstall_Click(object sender, EventArgs e)
        {
            #region Pre-Uninstallation

            _saved = Cursor;
            Cursor = Cursors.WaitCursor;

            btnInstall.Enabled = false;
            btnUninstall.Enabled = false;
            btnExit.Enabled = false;

            _busDeviceConfigured = false;
            _busDriverConfigured = false;
            _ds3DriverConfigured = false;
            _bthDriverConfigured = false;
            _scpServiceConfigured = false;

            pbRunning.Style = ProgressBarStyle.Marquee;

            #endregion

            #region Uninstallation

            await Task.Run(() =>
            {
                string devPath = string.Empty, instanceId = string.Empty;

                try
                {
                    var rebootRequired = false;

                    if (cbService.Checked)
                    {
                        IDictionary state = new Hashtable();
                        var service =
                            new AssemblyInstaller(Directory.GetCurrentDirectory() + @"\ScpService.exe", null);

                        state.Clear();
                        service.UseNewContext = true;

                        if (Stop(Settings.Default.ScpServiceName))
                        {
                            Logger(DifxLog.DIFXAPI_INFO, 0, Settings.Default.ScpServiceName + " Stopped.");
                        }

                        service.Uninstall(state);
                        _scpServiceConfigured = true;
                    }

                    if (cbBluetooth.Checked)
                    {
                        DriverInstaller.UninstallBluetoothDongles(ref rebootRequired);
                        _reboot |= rebootRequired;
                    }

                    if (cbDS3.Checked)
                    {
                        DriverInstaller.UninstallDualShock3Controllers(ref rebootRequired);
                        _reboot |= rebootRequired;
                    }

                    if (cbDs4.Checked)
                    {
                        DriverInstaller.UninstallDualShock4Controllers(ref rebootRequired);
                        _reboot |= rebootRequired;
                    }

                    if (cbBus.Checked && Devcon.Find(Settings.Default.Ds3BusClassGuid, ref devPath, ref instanceId))
                    {
                        if (Devcon.Remove(Settings.Default.Ds3BusClassGuid, devPath, instanceId))
                        {
                            Logger(DifxLog.DIFXAPI_SUCCESS, 0, "Virtual Bus Removed");
                            _busDeviceConfigured = true;

                            _installer.Uninstall(Path.Combine(Settings.Default.InfFilePath, @"ScpVBus.inf"),
                                DifxFlags.DRIVER_PACKAGE_DELETE_FILES,
                                out rebootRequired);
                            _reboot |= rebootRequired;
                        }
                        else
                        {
                            Logger(DifxLog.DIFXAPI_ERROR, 0, "Virtual Bus Removal Failure");
                        }
                    }
                }
                catch (InstallException instex)
                {
                    if (!(instex.InnerException is Win32Exception))
                    {
                        Log.ErrorFormat("Error during uninstallation: {0}", instex);
                        return;
                    }

                    switch (((Win32Exception) instex.InnerException).NativeErrorCode)
                    {
                        case 1060: // ERROR_SERVICE_DOES_NOT_EXIST
                            Log.Warn("Service doesn't exist, maybe it was uninstalled before");
                            break;
                        default:
                            Log.ErrorFormat("Win32-Error during uninstallation: {0}",
                                (Win32Exception) instex.InnerException);
                            break;
                    }
                }
                catch (Exception ex)
                {
                    Log.ErrorFormat("Error during uninstallation: {0}", ex);
                }
            });

            #endregion

            #region Post-Uninstallation

            pbRunning.Style = ProgressBarStyle.Continuous;

            btnInstall.Enabled = true;
            btnUninstall.Enabled = true;
            btnExit.Enabled = true;

            Cursor = _saved;

            Log.Info("Uninstall Succeeded.");
            if (_reboot)
                Log.Info(" [Reboot Required]");

            Log.Info("-- Uninstall Summary --");

            if (_scpServiceConfigured)
                Log.Info("SCP DS3 Service uninstalled");

            if (_busDeviceConfigured)
                Log.Info("Bus Device uninstalled");

            if (_busDriverConfigured)
                Log.Info("Bus Driver uninstalled");

            if (_ds3DriverConfigured)
                Log.Info("DS3 USB Driver uninstalled");

            if (_bthDriverConfigured)
                Log.Info("Bluetooth Driver uninstalled");

            #endregion
        }
Ejemplo n.º 29
0
Archivo: Program.cs Proyecto: vokac/F2B
 static void Install(bool undo, string[] args)
 {
     try
     {
         Log.Info(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 { }
                 throw;
             }
         }
     }
     catch (Exception ex)
     {
         Log.Error(ex.Message);
     }
 }
Ejemplo n.º 30
0
 /// <summary>
 /// 卸载服务
 /// </summary>
 /// <param name="filepath"></param>
 public static void uninstallmyservice(string filepath)
 {
     try
     {
         AssemblyInstaller assemblyinstaller1 = new AssemblyInstaller();
         assemblyinstaller1.UseNewContext = true;
         assemblyinstaller1.Path = filepath;
         assemblyinstaller1.Uninstall(null);
         assemblyinstaller1.Dispose();
     }
     catch(Exception e)
     {
         throw new Exception("请以管理员身份启动程序再执行此操作\n" + e.Message);
     }
 }
        private void Install(bool uninstall)
        {
            try
            {
                _log.Info(uninstall ? "Uninstalling" : "Installing");
                using (var inst = new AssemblyInstaller(typeof (Program).Assembly, null))
                {
                    IDictionary state = new Hashtable();
                    inst.UseNewContext = true;

                    try
                    {
                        if (uninstall)
                        {
                            inst.Uninstall(state);
                        }
                        else
                        {
                            inst.Install(state);
                            inst.Commit(state);
                        }
                    }
                    catch
                    {
                        try
                        {
                            inst.Rollback(state);
                        }
                        catch (Exception ex)
                        {
                            _log.Error("Error Rolling back");
                            _log.Error(ex.Message);
                        }
                        throw;
                    }
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex.Message);
            }
        }
Ejemplo n.º 32
-2
        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());
            }
        }