Example #1
0
 private static void InstallService()
 {
     //Install
     using (ProjectInstaller pi = new ProjectInstaller())
     {
         IDictionary savedState = new Hashtable();
         try
         {
             pi.Context = new InstallContext();
             pi.Context.Parameters.Add("assemblypath", Process.GetCurrentProcess().MainModule.FileName);
             foreach (Installer i in pi.Installers)
             {
                 i.Context = pi.Context;
             }
             pi.Install(savedState);
             pi.Commit(savedState);
             Trace.WriteLine("IzendaService successfully installed.");
         }
         catch (Exception ex)
         {
             pi.Rollback(savedState);
             Trace.WriteLine("IzendaService installing failed. " + ex.Message);
         }
     }
 }
Example #2
0
        private static void RemoveService()
        {
            //UnInstall
            using (ProjectInstaller pi = new ProjectInstaller())
            {
                try
                {
                    pi.Context = new InstallContext();
                    pi.Context.Parameters.Add("assemblypath", Process.GetCurrentProcess().MainModule.FileName);
                    foreach (Installer i in pi.Installers)
                    {
                        i.Context = pi.Context;
                    }

                    pi.Uninstall(null);
                    Trace.WriteLine("IzendaService successfully uninstalled.");
                }
                catch (Exception ex)
                {
                    Trace.WriteLine("IzendaService uninstalling failed. " + ex.Message);
                }
            }
        }