将文件类型与我的应用程序 C# 相关联

本文关键字:关联 应用程序 我的 文件 类型 | 更新日期: 2023-09-27 18:05:51


我一直在尝试让我的应用程序将某些文件类型与应用程序相关联。
如我所见,最简单的方法是更改 [HKEY_CLASSES_ROOT] 中的注册表。
但是,在 Windows 7(我猜到了(中,如果没有获得管理员权限,就无法做到这一点。
我已经纠结这个问题很长时间了,如果有人能指出我正确的方向,我将不胜感激。
我需要在注册表中创建和更改哪些值?什么价值观?(我的软件名称?什么描述?
多谢。

将文件类型与我的应用程序 C# 相关联

下面是.txt文件和TxtEditor之间关联的示例.exe

Windows 注册表编辑器版本 5.00

[HKEY_CLASSES_ROOT.txt] @="测试.txt">

[HKEY_CLASSES_ROOT''test.txt] @="文本文档">

[HKEY_CLASSES_ROOT''test.txt''DefaultIcon] @="%SystemRoot%''SysWow64''imageres.dll,-102">

[HKEY_CLASSES_ROOT''test.txt''shell]

[HKEY_CLASSES_ROOT''test.txt''shell''open]

[HKEY_CLASSES_ROOT''test.txt''shell''open''command] @="''"C:''TxtEditor.exe''" ''"%1''">

[HKEY_CLASSES_ROOT''test.txt''shell''print]

[HKEY_CLASSES_ROOT''test.txt''shell''print''command] @="''"C:''TxtEditor.exe''"/p ''"%1''">

也看看 http://www.codeproject.com/Articles/17023/System-File-Association

找到答案:为此,我创建了一个错误的文件类型并将其关联到我的程序。
然后,我在注册表中搜索更改并复制这些更改的路径。
代码在这里,如果有人有更好的答案,我想在这里。

'        public static void SetAssociation(string Extension, string KeyName, string OpenWith, string FileDescription(        {            注册表密钥打开方法;            注册表密钥文件扩展;
         //HKEY_CURRENT_USER'Software'Microsoft'Windows'CurrentVersion'Explorer'FileExts'.avi'UserChoice -->"Progid" "Applications'YEPlayer.exe"
        OpenMethod = Registry.CurrentUser.OpenSubKey(@"Software'Classes'Applications'", true);
        OpenMethod.CreateSubKey(KeyName + @".exe'shell'open'command").SetValue("",'"'+OpenWith+'"'+ " "+ '"'+"%1"+'"');
        FileExts = Registry.CurrentUser.OpenSubKey(@"Software'Microsoft'Windows'CurrentVersion'Explorer'FileExts'", true);
        foreach (string child in FileExts.OpenSubKey(Extension).GetSubKeyNames())
        {
            FileExts.OpenSubKey(Extension,true).DeleteSubKey(child);
        }
        FileExts.CreateSubKey(Extension + @"'UserChoice").SetValue("Progid", @"Applications'" + KeyName +".exe");
    }
 

'
多谢!