简体   繁体   English

如何获得“用..打开”功能的Windows命令行?

[英]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.

相关问题 如何以编程方式获取 Windows 命令行或 Windows 资源管理器的当前目录? - How to programmatically get current directory of a Windows command line or Windows explorer? 获取命令行请求的结果并打开文件 - Get result of command line request and open file 当我选择使用应用程序打开文件时,Windows传递给命令行参数的字符串的外观如何? - How does the string that windows passes into command line argument when I choose to open a file with my application look? 如何打开命令行 window 以运行另一个可移植可执行文件,然后从 Python 中获取 output? - How to open a command line window to run another portable executable and then get output from there in Python? 如何从Windows中的命令行运行Qt - How to run Qt from command line in windows 如何在 Windows 的命令行中编译 cpp 文件? - How to compile a cpp file in command line on Windows? 如何在 Windows 上从命令行运行 clang? - How run clang from command line on Windows? 如何从命令行在OSX的callgrind输出中获取有意义的函数名称? - How can I get meaningful function names in callgrind output on OSX from the command line? 如何获取原始命令行参数 - How to get the raw command line arguments 如何在 Xcode 之外打开从 Xcode 构建的命令行应用程序? - How to open Command Line application built from Xcode outside of Xcode?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM