确定所有可能的应用程序以使用 DelegateExecute 打开文件
Determine all posible applications to open a file with DelegateExecute
我想确定所有可能用于打开文件的应用程序。类似于资源管理器中的 "Open With" 上下文菜单。
来自注册表项:
HKEY_CLASSES_ROOT\extension\OpenWithProgids
我可以得到我要找的信息。这部分我很清楚。
但我也得到了一个条目,例如 "AppXea46y3k4tynme684q1dgefbnb0b9r8ec" 什么是 "CodeWriter" 一个 Windows 商店应用程序。
如果我在注册表中查找此条目:
HKEY_CLASSES_ROOT\AppXea46y3k4tynme684q1dgefbnb0b9r8ec
我发现了类似的东西:
HKEY_CLASSES_ROOT\AppXea46y3k4tynme684q1dgefbnb0b9r8ec\Shell\open\command
对于非商店应用程序,我会找到一个 shell 命令。喜欢:
"%ProgramFiles%\Windows NT\Accessories\WORDPAD.EXE" "%1"
从那里我可以确定程序(写字板),一切都很好。
对于商店应用程序,我发现类似:
此 DelegateExecute 值对于所有商店应用程序 ShellOpenCommands 都是相同的。
我想知道如何从那里获得可用的 OpenCommand。所以我可以确定它是什么应用程序。
SHAssocEnumHandlers 完成了工作。
我找到了 C++ 的示例实现:
#include "stdafx.h"
#include "Shobjidl.h"
int main(int argc, _TCHAR* argv[])
{
IEnumAssocHandlers *pEnumHandlers = NULL;
if (SUCCEEDED(SHAssocEnumHandlers(L".bmp", ASSOC_FILTER_RECOMMENDED, &pEnumHandlers)))
{
IAssocHandler *pAssocHandler = NULL;
while (S_OK == pEnumHandlers->Next(1, &pAssocHandler, NULL))
{
if (pAssocHandler != NULL)
{
LPWSTR pszName;
LPWSTR pszUIName;
LPWSTR ppszPath;
int pIndex;
pAssocHandler->GetUIName(&pszName);
pAssocHandler->GetName(&pszUIName);
pAssocHandler->GetIconLocation(&ppszPath, &pIndex);
pAssocHandler->Release();
pAssocHandler = NULL;
printf_s("%S \n", pszUIName);
printf_s("%S \n", pszName);
}
}
pEnumHandlers->Release();
scanf_s("%S");
}
return 0;
}
结果如下:
C:\Program Files (x86)\Windows Photo Viewer\PhotoViewer.dll
Windows-Fotoanzeige
C:\Windows\system32\mspaint.exe
Paint
对于 C# 实现,请参阅:
我想确定所有可能用于打开文件的应用程序。类似于资源管理器中的 "Open With" 上下文菜单。
来自注册表项:
HKEY_CLASSES_ROOT\extension\OpenWithProgids
我可以得到我要找的信息。这部分我很清楚。
但我也得到了一个条目,例如 "AppXea46y3k4tynme684q1dgefbnb0b9r8ec" 什么是 "CodeWriter" 一个 Windows 商店应用程序。
如果我在注册表中查找此条目:
HKEY_CLASSES_ROOT\AppXea46y3k4tynme684q1dgefbnb0b9r8ec
我发现了类似的东西:
HKEY_CLASSES_ROOT\AppXea46y3k4tynme684q1dgefbnb0b9r8ec\Shell\open\command
对于非商店应用程序,我会找到一个 shell 命令。喜欢:
"%ProgramFiles%\Windows NT\Accessories\WORDPAD.EXE" "%1"
从那里我可以确定程序(写字板),一切都很好。
对于商店应用程序,我发现类似:
此 DelegateExecute 值对于所有商店应用程序 ShellOpenCommands 都是相同的。
我想知道如何从那里获得可用的 OpenCommand。所以我可以确定它是什么应用程序。
SHAssocEnumHandlers 完成了工作。
我找到了 C++ 的示例实现:
#include "stdafx.h"
#include "Shobjidl.h"
int main(int argc, _TCHAR* argv[])
{
IEnumAssocHandlers *pEnumHandlers = NULL;
if (SUCCEEDED(SHAssocEnumHandlers(L".bmp", ASSOC_FILTER_RECOMMENDED, &pEnumHandlers)))
{
IAssocHandler *pAssocHandler = NULL;
while (S_OK == pEnumHandlers->Next(1, &pAssocHandler, NULL))
{
if (pAssocHandler != NULL)
{
LPWSTR pszName;
LPWSTR pszUIName;
LPWSTR ppszPath;
int pIndex;
pAssocHandler->GetUIName(&pszName);
pAssocHandler->GetName(&pszUIName);
pAssocHandler->GetIconLocation(&ppszPath, &pIndex);
pAssocHandler->Release();
pAssocHandler = NULL;
printf_s("%S \n", pszUIName);
printf_s("%S \n", pszName);
}
}
pEnumHandlers->Release();
scanf_s("%S");
}
return 0;
}
结果如下:
C:\Program Files (x86)\Windows Photo Viewer\PhotoViewer.dll
Windows-Fotoanzeige
C:\Windows\system32\mspaint.exe
Paint
对于 C# 实现,请参阅: