注册和卸载COM

 

/// <summary>
       
/// 注册COM+
       
/// </summary>
       
/// <param name="assembly"></param>
       
/// <param name="strErrorMessage"></param>
       
/// <returns></returns>
       public static bool Install(string assembly, ref string strErrorMessage)
       {
           bool flag = true;
           string applicationName = string.Empty;
           string typeLibraryName = string.Empty;
           try
           {
               flag = true;
               RegistrationHelper helper = new RegistrationHelper();
               helper.InstallAssembly(assembly, ref applicationName, ref typeLibraryName, InstallationFlags.CreateTargetApplication);
               strErrorMessage = string.Empty;
           }
           catch (Exception ex)
           {
               flag = false;
               strErrorMessage = ex.Message;
               //throw;
           }
           return flag;
       }


       /// <summary>
       
/// 卸栽COM+
       
/// </summary>
       
/// <param name="assembly"></param>
       
/// <param name="strErrorMessage"></param>
       
/// <returns></returns>
       public static bool UnInstall(string assembly, ref string strErrorMessage)
       {
           bool flag = true;
           string applicationName = string.Empty;
           string typeLibraryName = string.Empty;
           try
           {
               flag = true;
               RegistrationHelper helper = new RegistrationHelper();
               helper.UninstallAssembly(assembly,  applicationName,  typeLibraryName);
               strErrorMessage = string.Empty;
           }
           catch (Exception ex)
           {
               flag = false;
               strErrorMessage = ex.Message;
               //throw;
           }
           return flag;
       }
    } 

  

 

posted @ 2012-06-06 11:03  跟着阿笨一起玩.NET  阅读(989)  评论(0编辑  收藏  举报