Click here to Skip to main content
12,356,154 members (69,500 online)
Click here to Skip to main content

Stats

47K views
1.3K downloads
52 bookmarked
Posted

Creating and Installing Internet Explorer Context Menu using C#

, 9 Feb 2008 CPOL
Add an Internet Explorer context menu using an installer class
IEContextMenuSample
IEContextInstallerClass
bin
Debug
IEContextInstallerClass.dll
Properties
IEContextMenuSample.suo
IEContextMenuSample
Debug
IEContextMenuSample.msi
setup.exe
IEContextMenuSample.vdproj
Release
IEContextMenuSample.msi
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using Microsoft.Win32;

namespace IEContextInstallerClass
{
    [RunInstaller(true)]
    public partial class IEInstaller : Installer
    {
        public IEInstaller()
        {
            InitializeComponent();
        }

        public override void Install(System.Collections.IDictionary stateSaver)
        {
            base.Install(stateSaver);
            //grab the target director and add to install.installstate
            stateSaver.Add("TargetDir", Context.Parameters["DP_TargetDir"].ToString());
        }
        public override void Commit(System.Collections.IDictionary savedState)
        {
            base.Commit(savedState);

            //adding items to the context menu of IE
            RegistryKey key;
            string keyValueInt = "16";
            string subKey = @"SOFTWARE\Microsoft\Internet Explorer\MenuExt\Sample Action";
            key = Registry.CurrentUser.CreateSubKey(subKey);
            key.SetValue("Contexts", Convert.ToInt32(keyValueInt), RegistryValueKind.DWord);
            key.SetValue(null, "file://" + savedState["TargetDir"].ToString() + "\\action.html");
            key.Close();
        }
        protected override void OnBeforeUninstall(System.Collections.IDictionary savedState)
        {
            base.OnBeforeUninstall(savedState);
            //removing items from the context menu of IE
            string subKey = @"SOFTWARE\Microsoft\Internet Explorer\MenuExt\Sample Action";
            Registry.CurrentUser.DeleteSubKey(subKey);
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Riad MS Afyouni
Other Born Interactive
Saudi Arabia Saudi Arabia
Follow me: http://riadafyouni.blogspot.com

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160621.1 | Last Updated 10 Feb 2008
Article Copyright 2008 by Riad MS Afyouni
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid