惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

AI
AI
TaoSecurity Blog
TaoSecurity Blog
H
Heimdal Security Blog
Help Net Security
Help Net Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Microsoft Azure Blog
Microsoft Azure Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Google DeepMind News
Google DeepMind News
爱范儿
爱范儿
The Cloudflare Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
人人都是产品经理
人人都是产品经理
大猫的无限游戏
大猫的无限游戏
N
News | PayPal Newsroom
V2EX - 技术
V2EX - 技术
博客园 - 【当耐特】
D
Darknet – Hacking Tools, Hacker News & Cyber Security
S
Secure Thoughts
C
CERT Recently Published Vulnerability Notes
罗磊的独立博客
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Privacy & Cybersecurity Law Blog
有赞技术团队
有赞技术团队
S
Schneier on Security
S
SegmentFault 最新的问题
Google Online Security Blog
Google Online Security Blog
H
Hacker News: Front Page
The Last Watchdog
The Last Watchdog
Schneier on Security
Schneier on Security
PCI Perspectives
PCI Perspectives
IT之家
IT之家
Project Zero
Project Zero
博客园 - 司徒正美
P
Privacy International News Feed
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Jina AI
Jina AI
Security Latest
Security Latest
Hacker News - Newest:
Hacker News - Newest: "LLM"
腾讯CDC
C
CXSECURITY Database RSS Feed - CXSecurity.com
阮一峰的网络日志
阮一峰的网络日志
C
Check Point Blog
aimingoo的专栏
aimingoo的专栏
V
Vulnerabilities – Threatpost
W
WeLiveSecurity
NISL@THU
NISL@THU
Webroot Blog
Webroot Blog
N
Netflix TechBlog - Medium
L
Lohrmann on Cybersecurity

博客园 - 踏歌长行

前端知识质量内容网址 NuGet 质量博客链接 Entity Framework 质量博客链接 LINK1123:failure during conversion to COFF:file invalid or corrupt 未授权用户在此计算机上的请求登录类型 System.ServiceModel.AddressAccessDeniedException DataGrid 导出 Excel 中文乱码 80070005 Access is denied in Windows 2008 How to install ASP.NET 1.1 with IIS7 on Vista and Windows 2008 Unable to find script library '/aspnet_client/system-web/1-1-4322/webvalidation.js' JQuery file upload Access is denied in IE 7, 8, 9 ReportViewer 自适应高度 单元测试之模拟Mock 单元测试之 Xunit ASP.NET MVC ajax 提交列表到 Action VS 2010 制作 Windows Service 安装包之用户界面 VS 2010 制作 Windows Service 安装包 Postback 之后保持浏览器滚动条的位置 VS 2010 开发 ActiveX 制作 cab 包
VS 2010 开发 ActiveX 自动升级外篇
踏歌长行 · 2013-03-26 · via 博客园 - 踏歌长行

利用 ComRegisterFunction 特性在 Registry 中自动写入新的 InstalledVersion

1. 创建一个 Installer 类型的类

    [RunInstaller(true)]
    public partial class ComInstaller : System.Configuration.Install.Installer
    {
        public ComInstaller()
        {
            InitializeComponent();
        }

        public override void Install(IDictionary stateSaver)
        {
            base.Install(stateSaver);

            RegistrationServices regsrv = new RegistrationServices();
            if (!regsrv.RegisterAssembly(this.GetType().Assembly,
            AssemblyRegistrationFlags.SetCodeBase))
            {
                throw new InstallException("Failed To Register for COM");
            }
        }

        public override void Uninstall(IDictionary savedState)
        {
            base.Uninstall(savedState);

            RegistrationServices regsrv = new RegistrationServices();
            if (!regsrv.UnregisterAssembly(this.GetType().Assembly))
            {
                throw new InstallException("Failed To Unregister for COM");
            }
        }
    }


2. 为 Version 类写扩展方法 ToSpecialString()

        public static string ToSpecialString(this Version ver)
        {
            return string.Format("{0},{1},{2},{3}", ver.Major, ver.Minor, ver.Build, ver.Revision);
        }


3. InfoViewer 类中添加具有 ComRegisterFunction 特性的方法

        [ComRegisterFunction()]
        public static void RegisterClass(string key)
        {
            // Strip off HKEY_CLASSES_ROOT\ from the passed key as I don't need it
            StringBuilder sb = new StringBuilder(key);

            sb.Replace(@"HKEY_CLASSES_ROOT\", "");
            // Open the CLSID\{guid} key for write access
            RegistryKey k = Registry.ClassesRoot.OpenSubKey(sb.ToString(), true);

            // And create	the	'Control' key -	this allows	it to show up in
            // the ActiveX control container
            RegistryKey ctrl = k.CreateSubKey("Control");
            ctrl.Close();

            // Next create the CodeBase entry	- needed if	not	string named and GACced.
            RegistryKey inprocServer32 = k.OpenSubKey("InprocServer32", true);
            inprocServer32.SetValue("CodeBase", Assembly.GetExecutingAssembly().CodeBase);
            inprocServer32.Close();

            //Com Version
            RegistryKey instver = k.CreateSubKey("InstalledVersion");
            instver.SetValue("", Assembly.GetExecutingAssembly().GetName().Version.ToSpecialString());
            instver.Close();

            // Finally close the main	key
            k.Close();
        }

        [ComUnregisterFunction()]
        public static void UnregisterClass(string key)
        {
            StringBuilder sb = new StringBuilder(key);
            sb.Replace(@"HKEY_CLASSES_ROOT\", "");

            // Open	HKCR\CLSID\{guid} for write	access
            RegistryKey k = Registry.ClassesRoot.OpenSubKey(sb.ToString(), true);

            // Delete the 'Control'	key, but don't throw an	exception if it	does not exist
            k.DeleteSubKey("Control", false);

            // Next	open up	InprocServer32
            //RegistryKey	inprocServer32 = 
            k.OpenSubKey("InprocServer32", true);

            // And delete the CodeBase key,	again not throwing if missing
            k.DeleteSubKey("CodeBase", false);

            //Com Version
            k.DeleteSubKey("InstalledVersion");

            // Finally close the main key
            k.Close();
        }


4. 右键 ActiveXDemo.Setup 项目 --> View --> Custom Actions


5. 右键 Custom Actions --> Add Custom Action...


6. 点击 OK 之后


7. 重新编译,并制作 cab

通过这种设置,以后只需修改 ActiveX 的项目版本号,即可在安装时,系统自动写入 Registry 中的 InstalledVersion,其值为 ActiveX 的项目版本的值;但要注意,在修改 ActiveX 的项目版本号的同时,也要修改 HTML 中 codebase 中的版本号,使两者保持一致。