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

C# 将文件类型与我的应用程序C关联#,c#,registry,associations,C#,Registry,Associations,我一直在尝试让我的应用程序将某些文件类型与应用程序关联。 如我所见,最简单的方法是更改[HKEY_CLASSES_ROOT]中的注册表。 然而,在Windows7中(我猜是这样),没有管理员许可是无法做到的。 我已经纠缠这个问题很长时间了,如果有人能给我指出正确的方向,我将不胜感激。 我需要在注册表中创建和更改哪些值?什么价值观?(我的软件名?什么描述?) 非常感谢。下面是一个.txt文件和TxtEditor.exe之间关联的示例 Windows注册表编辑器5.00版 [HKEY_CLASSES


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

非常感谢。

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

Windows注册表编辑器5.00版

[HKEY_CLASSES_ROOT.txt]@=“test.txt”

[HKEY_CLASSES\u ROOT\test.txt]@=“文本文档”

[HKEY\U CLASSES\U ROOT\test.txt\DefaultIcon] @=%SystemRoot%\SysWow64\imageres.dll,-102

[HKEY\U CLASSES\U ROOT\test.txt\shell]

[HKEY\U CLASSES\U ROOT\test.txt\shell\open]

[HKEY\U CLASSES\U ROOT\test.txt\shell\open\command] @=“\”C:\TxtEditor.exe\“\%1”

[HKEY\U CLASSES\U ROOT\test.txt\shell\print]

[HKEY\U CLASSES\U ROOT\test.txt\shell\print\command] @=“\”C:\TxtEditor.exe\”/p\%1“

还可以查看

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

非常感谢

我的问题是我不能以编程方式更改HKEY\U类\U根<我怎样才能避免呢? ` public static void SetAssociation(string Extension, string KeyName, string OpenWith, string FileDescription) { RegistryKey OpenMethod; RegistryKey FileExts;

        //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");
    }