Bud*_*Joe 1 registry file-type
是否跳过注册表是询问哪些程序路径在Windows 7上打开此文件扩展名(.avi)的最佳方式?或者是否有更好的API使用?
在注册表中导航的正确方法是什么?我注意到当我安装DivX播放器时它从VLC播放器中偷走了.avi扩展名.我正好在文件的顶部并将默认程序设置为VLC,但我看不到它存储在HKCU中的哪个位置.
我的最终目标是让程序知道与文件扩展名相关联的应用程序.我想让它询问操作系统,而不是存储我自己的独立查找数据.
你不说你正在开发用什么语言,但是你应该能够调用做到这一点assocquerystring的shlwapi.dll.
该assocquerystringAPI函数将返回文件关联的数据,而不必手动潜入注册表和处理谎言中的恶魔.大多数语言都支持调用Windows API,所以你应该好好去.
更多信息可以在这里找到:
http://www.pinvoke.net/default.aspx/shlwapi.assocquerystring
和这里:
http://msdn.microsoft.com/en-us/library/bb773471%28VS.85%29.aspx
编辑:一些示例代码:
private void SomeProcessInYourApp()
{
// Get association for doc/avi
string docAsscData = AssociationsHelper.GetAssociation(".doc"); // returns : docAsscData = "C:\\Program Files\\Microsoft Office\\Office12\\WINWORD.EXE"
string aviAsscData = AssociationsHelper.GetAssociation(".avi"); // returns : aviAsscData = "C:\\Program Files\\Windows Media Player\\wmplayer.exe"
// Get association for an unassociated extension
string someAsscData = AssociationsHelper.GetAssociation(".blahdeblahblahblah"); // returns : someAsscData = "C:\\Windows\\system32\\shell32.dll"
}
internal static class AssociationsHelper
{
[DllImport("Shlwapi.dll", SetLastError = true, CharSet = CharSet.Auto)]
static extern uint AssocQueryString(AssocF flags, AssocStr str, string pszAssoc, string pszExtra,
[Out] StringBuilder pszOut, [In][Out] ref uint pcchOut);
[Flags]
enum AssocF
{
Init_NoRemapCLSID = 0x1,
Init_ByExeName = 0x2,
Open_ByExeName = 0x2,
Init_DefaultToStar = 0x4,
Init_DefaultToFolder = 0x8,
NoUserSettings = 0x10,
NoTruncate = 0x20,
Verify = 0x40,
RemapRunDll = 0x80,
NoFixUps = 0x100,
IgnoreBaseClass = 0x200
}
enum AssocStr
{
Command = 1,
Executable,
FriendlyDocName,
FriendlyAppName,
NoOpen,
ShellNewValue,
DDECommand,
DDEIfExec,
DDEApplication,
DDETopic
}
public static string GetAssociation(string doctype)
{
uint pcchOut = 0; // size of output buffer
// First call is to get the required size of output buffer
AssocQueryString(AssocF.Verify, AssocStr.Executable, doctype, null, null, ref pcchOut);
// Allocate the output buffer
StringBuilder pszOut = new StringBuilder((int)pcchOut);
// Get the full pathname to the program in pszOut
AssocQueryString(AssocF.Verify, AssocStr.Executable, doctype, null, pszOut, ref pcchOut);
string doc = pszOut.ToString();
return doc;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1268 次 |
| 最近记录: |