Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
 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());
     }
 }
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
        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.º 5
0
 /// <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);
     }
 }
Ejemplo n.º 6
0
        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;
            }
        }
Ejemplo n.º 7
0
        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;
        }
Ejemplo n.º 8
0
 /// <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();
 }
        /// <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);
            }
        }
Ejemplo n.º 10
0
        /// <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);
        }
Ejemplo n.º 11
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.º 12
0
        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();
        }
Ejemplo n.º 13
0
        public static bool Install()
        {
            Tracker.StartServer();

            bool result = true;

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

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

            return result;
        }
Ejemplo n.º 14
0
 /// <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());
     }
 }
Ejemplo n.º 15
0
 // References http://stackoverflow.com/questions/1195478/how-to-make-a-net-windows-service-start-right-after-the-installation/1195621#1195621
 public static void Install()
 {
     using (AssemblyInstaller installer =
             new AssemblyInstaller(typeof(OpenVpnService).Assembly, null))
     {
         installer.UseNewContext = true;
         var state = new System.Collections.Hashtable();
         try
         {
             installer.Install(state);
             installer.Commit(state);
         } catch
         {
             installer.Rollback(state);
             throw;
         }
     }
 }
Ejemplo n.º 16
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);
            }
        }
Ejemplo n.º 17
0
		public void OnAction(Hashtable parameters)
		{
			ArrayList temp = new ArrayList();
			temp.Add("/LogToConsole=false");
			StringBuilder tempString = new StringBuilder();
			foreach(DictionaryEntry entry in parameters)
			{
				if(tempString.Length > 0)
					tempString.Append(" ");
				tempString.Append(entry.Key);
				tempString.Append("=");
				tempString.Append(entry.Value);
			}
			temp.Add("commandline="+tempString.ToString());
			
			string[] commandLine = (string[]) temp.ToArray(typeof(string));

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

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

			Console.WriteLine("Installing DOL as system service...");
			try
			{
				asmInstaller.Install(rollback);
				asmInstaller.Commit(rollback);
			}
			catch (Exception e)
			{
				asmInstaller.Rollback(rollback);
				Console.WriteLine("Error installing as system service");
				Console.WriteLine(e.Message);
				return;
			}
			Console.WriteLine("Finished!");
		}
        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.º 19
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.º 20
0
 /// <summary>
 /// 安装windows服务
 /// </summary>
 /// <param name="serviceName">服务名称</param>
 /// <param name="savedState">它用于保存执行提交、回滚或卸载操作所需的信息。</param>
 /// <param name="filepath">获取或设置要安装的程序集的路径。</param>
 public static void InstallService(String serviceName, IDictionary savedState, string filepath)
 {
     ServiceController service = new ServiceController(serviceName);
     if (!ServiceIsExisted(serviceName))
     {
         AssemblyInstaller myAssemblyInstaller = new AssemblyInstaller();
         myAssemblyInstaller.UseNewContext = true;
         myAssemblyInstaller.Path = filepath;
         myAssemblyInstaller.Install(savedState);
         myAssemblyInstaller.Commit(savedState);
         myAssemblyInstaller.Dispose();
         service.Start();
     }
     else
     {
         if (service.Status != ServiceControllerStatus.Running && service.Status != ServiceControllerStatus.StartPending)
         {
             service.Start();
         }
     }
 }
Ejemplo n.º 21
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.º 22
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);
     }
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="exeFilename">Installer class (not the service class!)</param>
        /// <param name="exception"></param>
        /// <returns></returns>
        public static bool InstallService(string exeFilename, out Exception exception)
        {
            exception = null;
            string[] commandLineOptions = new string[1] {
                "/LogFile=install.log"
            };

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

            try
            {
                installer.UseNewContext = true;
                installer.Install(null);
                installer.Commit(null);
            }
            catch (Exception ex)
            {
                exception = ex;
                return(false);
            }
            return(true);
        }
Ejemplo n.º 24
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.º 26
0
        private async void btnInstall_Click(object sender, EventArgs e)
        {
            #region Pre-Installation

            _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;

            var forceInstall = cbForce.Checked;
            var installBus = cbBus.Checked;
            var installBth = cbBluetooth.Checked;
            var installDs3 = cbDS3.Checked;
            var installDs4 = cbDs4.Checked;
            var installService = cbService.Checked;

            #endregion

            #region Installation

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

                try
                {
                    uint result = 0;

                    var flags = DifxFlags.DRIVER_PACKAGE_ONLY_IF_DEVICE_PRESENT;

                    if (forceInstall)
                        flags |= DifxFlags.DRIVER_PACKAGE_FORCE;

                    if (installBus)
                    {
                        if (!Devcon.Find(Settings.Default.Ds3BusClassGuid, ref devPath, ref instanceId))
                        {
                            if (Devcon.Create("System", new Guid("{4D36E97D-E325-11CE-BFC1-08002BE10318}"),
                                "root\\ScpVBus\0\0"))
                            {
                                Logger(DifxLog.DIFXAPI_SUCCESS, 0, "Virtual Bus Created");
                                _busDeviceConfigured = true;
                            }
                        }

                        bool rebootRequired;
                        result = _installer.Install(Path.Combine(Settings.Default.InfFilePath, @"ScpVBus.inf"), flags,
                            out rebootRequired);
                        _reboot |= rebootRequired;
                        if (result == 0) _busDriverConfigured = true;
                    }

                    if (installBth)
                    {
                        Invoke(
                            (MethodInvoker) delegate { result = DriverInstaller.InstallBluetoothDongles(Handle, forceInstall); });
                        if (result > 0) _bthDriverConfigured = true;
                    }

                    if (installDs3)
                    {
                        Invoke(
                            (MethodInvoker)
                                delegate { result = DriverInstaller.InstallDualShock3Controllers(Handle, forceInstall); });
                        if (result > 0) _ds3DriverConfigured = true;
                    }

                    if (installDs4)
                    {
                        Invoke(
                            (MethodInvoker)
                                delegate { result = DriverInstaller.InstallDualShock4Controllers(Handle, forceInstall); });
                        if (result > 0) _ds4DriverConfigured = true;
                    }

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

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

                        service.Install(state);
                        service.Commit(state);

                        if (Start(Settings.Default.ScpServiceName))
                            Logger(DifxLog.DIFXAPI_INFO, 0, Settings.Default.ScpServiceName + " Started.");
                        else _reboot = true;

                        _scpServiceConfigured = true;
                    }
                }
                catch (Win32Exception w32Ex)
                {
                    switch (w32Ex.NativeErrorCode)
                    {
                        case 1073: // ERROR_SERVICE_EXISTS
                            Log.WarnFormat("Service already exists, skipping installation...");
                            break;
                        default:
                            Log.ErrorFormat("Win32-Error during installation: {0}", w32Ex);
                            break;
                    }
                }
                catch (Exception ex)
                {
                    Log.ErrorFormat("Error during installation: {0}", ex);
                }
            });

            #endregion

            #region Post-Installation

            pbRunning.Style = ProgressBarStyle.Continuous;

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

            Cursor = _saved;

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

            Log.Info("-- Install Summary --");
            if (_scpServiceConfigured)
                Log.Info("SCP DS3 Service installed");

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

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

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

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

            if (_ds4DriverConfigured)
                Log.Info("DS4 USB Driver installed");

            #endregion
        }
Ejemplo n.º 27
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.º 28
0
 /// <summary>
 /// Installs the service
 /// </summary>
 void Install()
 {
     Console.Write(InfoString);
     try {
         using (var i = new AssemblyInstaller(ProgramType.Assembly, null) { UseNewContext = true }) {
             var s = new Hashtable();
             try {
                 i.Install(s);
                 i.Commit(s);
             } catch {
                 try {
                     i.Rollback(s);
                 } catch { }
                 throw;
             }
         }
         Console.WriteLine(Messages.Done);
     } catch (Exception x) {
         Console.Error.WriteLine(x.Message);
         ReturnValue = 1;
     }
 }
Ejemplo n.º 29
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.º 31
-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());
            }
        }