目标是通过Windows ::ShellExecuteExW
打印一个htm/html文件。
::ShellExecuteExW
的参数如下
shell_info.lpVerb = "open";
shell_info.lpFile = "C:\Windows\System32\rundll32.exe";
shell_info.lpParameters = "C:\Windows\System32\mshtml.dll ,PrintHTML "C:\Temp\test.html"";
lpFile
和lpParameters
是从注册表项"\HKEY_CLASSES_ROOT\htmlfile\shell\print\command"
获取的。
错误信息:
如果通过cmd运行C:\Windows\system32\rundll32.exe C:\Windows\system32\mshtml.dll ,PrintHTML "C:\Temp\test.html"
,一切都很好。将显示打印对话框。
如何调用::ShellExecuteExW
以实现与cmd相同的行为?
发布于 2022-05-30 09:12:13
在屏幕截图中生成错误的代码是否可能与您在这里展示的不同?我这么问是因为你似乎逃不出任何双引号或反斜杠。在我看来,您的编译器在编译代码时至少应该给出一个错误。
然而,我只是尝试了下面的代码,这似乎是可行的。希望能帮上忙。
int main()
{
SHELLEXECUTEINFOW shell_info = { 0 };
shell_info.cbSize = sizeof(SHELLEXECUTEINFOW);
shell_info.lpVerb = L"open";
shell_info.lpFile = L"C:\\Windows\\System32\\rundll32.exe";
shell_info.lpParameters = L"C:\\Windows\\System32\\mshtml.dll ,PrintHTML \"C:\\Temp\\test.html\"";
shell_info.nShow = SW_SHOWNORMAL;
ShellExecuteExW(&shell_info);
return 0;
}
https://stackoverflow.com/questions/72431265
复制相似问题