简体   繁体   English

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

[英]Associate file types with my application C#


I have been trying to get my application to associate certain file types with the app. 我一直在尝试让我的应用程序将某些文件类型与该应用程序关联。
The easiest way as I have seen is to change the registry in [HKEY_CLASSES_ROOT]. 如我所见,最简单的方法是更改​​[HKEY_CLASSES_ROOT]中的注册表。
However, in windows 7 (and i'm guessing up) there is no way to do so without getting admin permission. 但是,在Windows 7中(我正在猜测), 没有获得管理员许可就无法这样做。
I have been tangling this issue for a very long time and I would appreciate if someone would point me in the right direction. 我纠结这个问题已经很长时间了,如果有人能指出我正确的方向,我将不胜感激。
Which values do I need to create and change in the registry? 我需要在注册表中创建和更改哪些值? To what values? 什么值? (My software name? What description?) (我的软件名称?什么描述?)
Thanks alot. 非常感谢。

Just an example below of association between .txt files and TxtEditor.exe 下面是.txt文件和TxtEditor.exe之间关联的一个示例

Windows Registry Editor Version 5.00 Windows注册表编辑器版本5.00

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

[HKEY_CLASSES_ROOT\\test.txt] @="Text Document" [HKEY_CLASSES_ROOT \\ test.txt] @ =“文本文档”

[HKEY_CLASSES_ROOT\\test.txt\\DefaultIcon] @="%SystemRoot%\\SysWow64\\imageres.dll,-102" [HKEY_CLASSES_ROOT \\ test.txt \\ DefaultIcon] @ =“%SystemRoot%\\ SysWow64 \\ imageres.dll,-102”

[HKEY_CLASSES_ROOT\\test.txt\\shell] [HKEY_CLASSES_ROOT \\ test.txt的\\壳]

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

[HKEY_CLASSES_ROOT\\test.txt\\shell\\open\\command] @="\\"C:\\TxtEditor.exe\\" \\"%1\\"" [HKEY_CLASSES_ROOT \\ test.txt \\ shell \\ open \\ command] @ =“ \\” C:\\ TxtEditor.exe \\“ \\”%1 \\“”

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

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

Also have a look at http://www.codeproject.com/Articles/17023/System-File-Association 也可以看看http://www.codeproject.com/Articles/17023/System-File-Association

Found the answer: For that I created a faulty file type and associated it to my program. 找到了答案:为此,我创建了错误的文件类型并将其与程序关联。
Then I searched the registry for changes and copied the pathes of those changes. 然后,我在注册表中搜索更改,并复制了这些更改的路径。
The code is here and I would like to here if anyone has a better answer. 代码在这里,如果有人有更好的答案,我想在这里。

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

'
Thanks alot! 非常感谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM