现在的位置: 首页 > 综合 > 正文

Associate extension with c# exe

2012年12月14日 ⁄ 综合 ⁄ 共 756字 ⁄ 字号 评论关闭

Code as follow:

    public static class AssociateExtensionHelper
    {
        public static void CreateExtension(string extension, string commandPath)
        {
            string operationkeyName = "Do" + extension;
            var key = Registry.ClassesRoot.CreateSubKey(extension);
            key.SetValue(null, operationkeyName);

            var operationkey = Registry.ClassesRoot.CreateSubKey(operationkeyName);
            var defaultIcon = operationkey.CreateSubKey("DefaultIcon");
            defaultIcon.SetValue(null, "%SystemRoot%\\SysWow64\\imageres.dll,-103");

            var shellKey = operationkey.CreateSubKey("shell");
            var openKey = shellKey.CreateSubKey("Open");
            var commandKey = openKey.CreateSubKey("command");
            commandKey.SetValue(null, commandPath);
        }
    }

Call as this :

AssociateExtensionHelper.CreateExtension(".abc", @"E:\MyDemo\MyDemo\AssociateExtension\bin\Debug\AssociateExtension.exe %1");

 

 

 

 

 

抱歉!评论已关闭.