Home > Enterprise >  How to print .html files using ShellExecuteExW?
How to print .html files using ShellExecuteExW?

Time:05-30

The goal is to print a htm/html file via Windows-API ::ShellExecuteExW.

The parameters of ::ShellExecuteExW are

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 and lpParameters are fetched from the registry key "\HKEY_CLASSES_ROOT\htmlfile\shell\print\command"

The error message: enter image description here

Everything is fine if running the C:\Windows\system32\rundll32.exe C:\Windows\system32\mshtml.dll ,PrintHTML "C:\Temp\test.html" via cmd. The printing dialog appears.

How does ::ShellExecuteExW need to be called to achieve the same behavior as the cmd?

CodePudding user response:

Is it possible that the code that generates the error in the screenshot looks different from what you show us here? I'm asking this because you don't seem to escape any double quote or backslash. Seems to me your compiler should at least give one error when compiling that code.

However I just tried the code below and this seem to work. Hope it helps.

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;
}
  • Related