使用 ShellExecuteEx 打开一个可执行文件,同时指定一个 lpClass? [英] Using ShellExecuteEx to open an executable, also specifying an lpClass?

查看:29
本文介绍了使用 ShellExecuteEx 打开一个可执行文件,同时指定一个 lpClass?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读this并了解lpClass 可用于修复错误的文件扩展名问题".但是,当我阅读以下代码行时,我无法弄清楚打开可执行文件时lpClass的用途.

I have read this and understand lpClass can be used to fix the "wrong file extension issue". However, when I am reading the following lines of code, I can't figure out what lpClass is used for when opening an executable file.

//code excerpt from foo.exe
SHELLEXECUTEINFO info;
ZeroMemory(&info, sizeof(SHELLEXECUTEINFO));
info.cbSize = sizeof(SHELLEXECUTEINFO);
info.nShow = SW_NORMAL;
info.lpVerb = L"open";
info.lpClass = L"ProgId Of foo.exe"; //what is this used for???
info.fMask = SEE_MASK_FLAG_LOG_USAGE | SEE_MASK_CLASSNAME;    
info.lpFile = L"bar.exe";
info.lpParameters = lpszParam;
ShellExecuteEx(&info);

如果没有指定 lpClass,如果 lpVerb 是open"并且 lpFile 是一个 exe,那么运行代码只会执行这个 exe.但是如果在这种情况下指定 lpClass 呢?

Without lpClass being specified, if lpVerb is "open" and lpFile is an exe, running the code simply executes the exe. But what if lpClass is specified as in this case?

推荐答案

参数 lpClass 应该是文件类型的 progID.这是什么意思?

The parameter lpClass should be the progID of the file type. What does that mean?

好吧,想想如果你没有通过课程会发生什么.

Well consider what happens if you don't pass the class.

  1. 实际上,这意味着 Shell 在注册表中的 HKEY_CLASSES_ROOT\.htm 下查找文件扩展名(例如 .htm).然后它检查默认值,通常是 htmlfile.(它也使用其他技巧,但在绝大多数情况下,是扩展名决定了 progid).

  1. In reality, it means the Shell looks up the file extension (e.g. .htm) in the registry, under HKEY_CLASSES_ROOT\.htm. Then it checks the default value which is generally htmlfile. (It also uses other tricks, but in the vast majority of cases it's the extension which determines the progid).

接下来查找HKEY_CLASSES_ROOT\htmlfile,并使用那里的信息(在HKEY_CLASSES_ROOT\htmlfile\shell\open下)决定如何打开文件.

Next it looks up HKEY_CLASSES_ROOT\htmlfile, and uses the information there (under HKEY_CLASSES_ROOT\htmlfile\shell\open) to decide how to open the file.

那么你如何使用lpClass?好吧,例如,假设您有一个 .TXT 文件,但您知道它确实是 html,您可以将 "htmlfile" 作为 lpclass 传递> 参数.这将跳过第 1 步(查看文件扩展名以查找类)并直接进入第 2 步.这(通常)会导致在浏览器而不是记事本中打开文件.

So how do you use lpClass? Well, for example, suppose you have an .TXT file, but you know it is really html, you can pass "htmlfile" as the lpclass parameter. This will skip the step 1 (looking at the file extension to find the class) and go straight to step 2. This will (usually) cause the file to be opened in a browser instead of notepad.

在您的示例中,您已将 "bar.exe" 作为 lpFile 参数传递.如果您将 "txtfile" 作为 lpClass 传递,您会发现它不是运行 bar.exe,而是在记事本中打开它.

In your example you have passed "bar.exe" as the lpFile parameter. If you pass "txtfile" as lpClass you should find that instead of running bar.exe it opens it in notepad.

这篇关于使用 ShellExecuteEx 打开一个可执行文件,同时指定一个 lpClass?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆