[英]How to get command line of windows “open with ..” function?
I previously asked a question that is about how to get windows "open with.." application list. 我之前曾问过一个有关如何使Windows“以..打开”应用程序列表的问题。 Here's a link to that question.
这是该问题的链接 。
We can use SHAssocEnumHandlers
interface to get the file association with specific file extension, ex .png
我们可以使用
SHAssocEnumHandlers
接口来获取具有特定文件扩展名的文件关联,例如.png
Then use IAssocHandler and can retrieves the full path and file name of the executable file associated with the file type( .png
). 然后使用IAssocHandler并可以检索与文件类型(
.png
)关联的可执行文件的完整路径和文件名。 ex: ['Paint': 'C:\\\\Windows\\\\system32\\\\mspaint.exe', ...]
例如:
['Paint': 'C:\\\\Windows\\\\system32\\\\mspaint.exe', ...]
But I want to get the command line of executing mspaint.exe with a given image. 但是我想获得使用给定图像执行mspaint.exe的命令行。 Like this~
"%systemroot%\\system32\\mspaint.exe" "%1"
像这样〜
"%systemroot%\\system32\\mspaint.exe" "%1"
Is there another msdn api could help us to get the "open with.." command? 是否有另一个msdn api可以帮助我们获取“ open with ..”命令? I think it should have, since windows XP already have this ability.
我认为应该有,因为Windows XP已经具有此功能。
Use AssocQueryString(..., ASSOCSTR_COMMAND, ...);
使用
AssocQueryString(..., ASSOCSTR_COMMAND, ...);
Example: 例:
TCHAR commandline[1024];
DWORD size = ARRAYSIZE(commandline);
AssocQueryString(0, ASSOCSTR_COMMAND, _T(".txt"), 0, commandline, &size);
There is the SHOpenWithDialog
function. 有
SHOpenWithDialog
函数。
Link to SHOpenWithDialog on MSDN 链接到MSDN上的SHOpenWithDialog
However, you can't use this to retrieve the selected program. 但是,您不能使用它来检索选定的程序。 You can only use it to invoke the "Open With" behaviour and eventually open the file (if
OAIF_EXEC
is set). 您只能使用它来调用“打开方式”行为并最终打开文件(如果设置了
OAIF_EXEC
)。 If that's all you're interested in, then try it out: 如果这就是您感兴趣的全部,请尝试一下:
#include <windows.h>
#include <Shlobj.h>
#pragma comment(lib, "Shell32.lib")
int main()
{
OPENASINFO info = { 0 };
info.pcszFile = L"C:\\Temp\\SomeFile.png";
info.pcszClass = NULL;
info.oaifInFlags = OAIF_ALLOW_REGISTRATION | OAIF_EXEC;
SHOpenWithDialog(NULL, &info);
return 0;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.