How do I uninstall the GAC from my C# application.

I am not able to uninstall, the particular exe and DLL from GAC.

Is it the proper way to uninstall the GAC in C# ?

public void RemoveAssembly(string ShortAssemblyName, string PublicToken)
{
AssemblyCacheEnum AssembCache = new AssemblyCacheEnum(null); string FullAssembName = null; for (; ; )
{
string AssembNameLoc = AssembCache.GetNextAssembly();
if (AssembNameLoc == null)
break; string Pt;
string ShortName = GetAssemblyShortName(AssembNameLoc, out Pt); if (ShortAssemblyName == ShortName)
{ if (PublicToken != null)
{
PublicToken = PublicToken.Trim().ToLower();
if (Pt == null)
{
FullAssembName = AssembNameLoc;
break;
} Pt = Pt.ToLower().Trim(); if (PublicToken == Pt)
{
FullAssembName = AssembNameLoc;
break;
}
}
else
{
FullAssembName = AssembNameLoc;
break;
}
}
} string Stoken = "null";
if (PublicToken != null)
{
Stoken = PublicToken;
} if (FullAssembName == null)
throw new Exception("Assembly=" + ShortAssemblyName + ",PublicToken=" +
token + " not found in GAC"); AssemblyCacheUninstallDisposition UninstDisp; AssemblyCache.UninstallAssembly(FullAssembName, null, out UninstDisp);
} public static void UninstallAssembly(String assemblyName, InstallReference reference, out AssemblyCacheUninstallDisposition disp)
{
AssemblyCacheUninstallDisposition dispResult = AssemblyCacheUninstallDisposition.Uninstalled;
if (reference != null)
{
if (!InstallReferenceGuid.IsValidGuidScheme(reference.GuidScheme))
throw new ArgumentException("Invalid reference guid.", "guid");
} IAssemblyCache ac = null; int hr = Utils.CreateAssemblyCache(out ac, 0);
if (hr >= 0)
{
hr = ac.UninstallAssembly(0, assemblyName, reference, out dispResult);
} if (hr < 0)
{
Marshal.ThrowExceptionForHR(hr);
} disp = dispResult;
}

  

Uninstall from GAC In C# code的更多相关文章

  1. Android Security

    Android Security¶ 确认签名¶ Debug签名: $ jarsigner -verify -certs -verbose bin/TemplateGem.apk sm 2525 Sun ...

  2. 如何使用OpenCart 2.x Event事件系统

    如何使用OpenCart 2.x Event事件系统 OpenCart 2.x 包含很多新特性,其中之一就是专为开发者提供的事件系统,Event System.它允许你在不修改原有系统代码的基础上( ...

  3. 【转载】使用appium遇到的坑

    问题 1. error: Failed to start an Appium session, err was: Error: Requested a new session but one was ...

  4. Intent.java分析

    代码位于frameworks/base/core/java/anroid/Content/Intent.java Intent是对要进行操作的一种抽象描述.用action抽象操作,用data(andr ...

  5. Appium的一些问题的总结答案

        问题 1. error: Failed to start an Appium session, err was: Error: Requested a new session but one ...

  6. SQL1159 Initialization error with DB2 .NET Data Provider, reason code 7(问题补充)

    SQL1159 Initialization error with DB2 .NET Data Provider, reason code 7 需要注册GAC,修改注册表 IBM官方方案: http: ...

  7. using inno setup uninstall default icon

    If you set SetupIconFile then the Uninstall Exe File (e.g. unins000.exe) will have exactly same icon ...

  8. Gumshoe - Microsoft Code Coverage Test Toolset

    Gumshoe - Microsoft Code Coverage Test Toolset 2014-07-17 What is Gumshoe? How to instrument a binar ...

  9. 【转】adb uninstall卸载apk文件说明

    昨天在使用adb卸载程序,结果死活卸载不了.我输入的命令和系统提示如下: [plain] view plaincopy   arthur@arthur-laptop:~$ adb uninstall  ...

随机推荐

  1. iOS之UIApplication详解

    UIApplication对象特点: 特点1: UIApplication对象是应用程序的象征,一个UIApplication对象就代表一个应用程序,而且是单例的.(用来封装整个应用程序的一个对象, ...

  2. Android进度条学习

    自定义属性 <!-- roundColor 圆环的颜色 roundProgressColor 进度的颜色 roundWidth 圆环的宽度 textColor 文字颜色 textSize 文字大 ...

  3. iOS json解析的几种方法 NSJSONSerialization,JSONKit,SBJson ,TouchJson

    相关的第三方类库大家可以去github上下载 1.NSJSONSerialization 具体代码如下 : - (void)viewDidLoad { [super viewDidLoad]; NSD ...

  4. git笔记

    这篇有关git的博客,写着写着有些崩了.里面有些碎碎念了.下次一定注意这个问题. 创建项目: midir xx :创建xx文件夹 git init : 为当前文件夹创建代码仓库 提交代码: git a ...

  5. MyBatis Generator作为maven插件自动生成增删改查代码及配置文件例子

    什么是MyBatis Generator MyBatis Generator (MBG) 是一个Mybatis的代码生成器,可以自动生成一些简单的CRUD(插入,查询,更新,删除)操作代码,model ...

  6. Expdp 导数错误 ORA-00832

    问题实验环境 操作系统:Red Hat Enterprise Linux Server release 5.7 (Tikanga) 数据库  :Oracle Database 10g Release ...

  7. 推荐一个不错的css3网站 可以直接调用的

    animate.css 一搜就能出来  我用着还不错

  8. eclipse编辑jsp保存的时候特别卡解决办法

    今天eclipse用着用着的时候,每次编辑jsp页面快捷键保存的时候要等半天才保存好,特别的卡.搞的很蛋疼.上网搜了下有解决办法 Window -> Preference -> Gener ...

  9. gdb脚本

    一.简介 作为UNIX/Linux下使用广泛的调试器,gdb不仅提供了丰富的命令,还引入了对脚本的支持:一种是对已存在的脚本语言支持,比如python,用户可以直接书写python脚本,由gdb调用p ...

  10. WPF Tranform-Flip Image

    Use a ScaleTransform with a ScaleX of -1 for horizontal and ScaleY of -1 for vertical flipping, appl ...