GME  13
Registrar.cs
Go to the documentation of this file.
00001 using System;
00002 using System.Collections.Generic;
00003 using System.Linq;
00004 using System.Text;
00005 using System.Security.Principal;
00006 using System.Runtime.InteropServices;
00007 using System.Reflection;
00008 
00009 namespace MGA.DotNetServices
00010 {
00011     [Guid("0BB0C371-6835-4F09-A156-0BD8E3DF8216"),
00012     ProgId("MGA.DotNetRegistrar"),
00013     ClassInterface(ClassInterfaceType.AutoDual)]
00014     [ComVisible(true)]
00015     public class Registrar
00016     {
00017         public void Register(String filename)
00018         {
00019             // bool isElevated = new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator);
00020             RegistrationServices regasm = new RegistrationServices();
00021             Assembly asm = Assembly.LoadFrom(filename);
00022             try
00023             {
00024                 regasm.RegisterAssembly(asm, AssemblyRegistrationFlags.SetCodeBase);
00025             }
00026             catch (System.Reflection.TargetInvocationException e)
00027             {
00028                 throw e.GetBaseException();
00029             }
00030         }
00031 
00032         public void Unregister(String filename)
00033         {
00034             RegistrationServices regasm = new RegistrationServices();
00035             Assembly asm = Assembly.LoadFrom(filename);
00036             try
00037             {
00038                 regasm.UnregisterAssembly(asm);
00039             }
00040             catch (System.Reflection.TargetInvocationException e)
00041             {
00042                 throw e.GetBaseException();
00043             }
00044         }
00045     }
00046 }