[英]Associate file types with my application C#
我一直在嘗試讓我的應用程序將某些文件類型與該應用程序關聯。
如我所見,最簡單的方法是更改[HKEY_CLASSES_ROOT]中的注冊表。
但是,在Windows 7中(我正在猜測), 沒有獲得管理員許可就無法這樣做。
我糾結這個問題已經很長時間了,如果有人能指出我正確的方向,我將不勝感激。
我需要在注冊表中創建和更改哪些值? 什么值? (我的軟件名稱?什么描述?)
非常感謝。
下面是.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 \\ shell \\ open \\ command] @ =“ \\” C:\\ TxtEditor.exe \\“ \\”%1 \\“”
[HKEY_CLASSES_ROOT \\ test.txt的\\殼\\打印]
[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)
{
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");
}
“
非常感謝!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.