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

时间:2014-05-28 23:49:27

标签: c# registry associations


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

2 个答案:

答案 0 :(得分:0)

下面是.txt文件与TxtEditor.exe

之间关联的示例
  

Windows注册表编辑器版本5.00

     

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

     

[HKEY_CLASSES_ROOT \ test.txt] @ =“文字文件”

     

[HKEY_CLASSES_ROOT \ test.txt的\的DefaultIcon]   @ = “%SYSTEMROOT%\ SYSWOW64 \ imageres.dll,-102”

     

[HKEY_CLASSES_ROOT \ test.txt的\壳]

     

[HKEY_CLASSES_ROOT \ test.txt的\壳\开放]

     

[HKEY_CLASSES_ROOT \ test.txt的\壳\开放\命令]   @ =“\”C:\ TxtEditor.exe \“\”%1 \“”

     

[HKEY_CLASSES_ROOT \ test.txt的\壳\打印]

     

[HKEY_CLASSES_ROOT \ test.txt的\壳\打印\命令]   @ =“\”C:\ TxtEditor.exe \“/ p \”%1 \“”

另请查看http://www.codeproject.com/Articles/17023/System-File-Association

答案 1 :(得分:0)

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

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

'
非常感谢!