PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, September 15, 2022

[FIXED] How to print .html files using ShellExecuteExW?

 September 15, 2022     c++, printing, winapi, windows     No comments   

Issue

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?


Solution

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


Answered By - Tycho
Answer Checked By - Clifford M. (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing