0

I've a *.mht file (say, abc.mht) which opens in IE explorer manually. I want to automate this process (programatically from c++) of 1) opening the abc.mht file 2) Keeping it open for few seconds 3) Then, close the abc.mht file from within my c++ program.

I've been using the below command for running EXEs from my c++ code. But I can't use the similar analogy for opening *.mht files.

Can anyone plz help me to programatically open *.mht files. Thnaks.

STARTUPINFO sInfo;
    memset( &sInfo, 0, sizeof(sInfo) );
    sInfo.cb = sizeof(sInfo);
    sInfo.dwFlags = STARTF_USESHOWWINDOW;
    sInfo.wShowWindow = SW_SHOWMAXIMIZED;

    PROCESS_INFORMATION pInfo;
    memset( &pInfo, 0, sizeof(pInfo) );

    CreateProcess(NULL, _T(Path), NULL, NULL, FALSE, 0, NULL, _T(workDir), &sInfo, &pInfo))
codeLover
  • 3,720
  • 10
  • 65
  • 121
  • 1
    CreateProcess() can only start executable files. ShellExecuteEx() knows how to use a file association, a shell implementation detail. – Hans Passant Jul 30 '14 at 16:03
  • Internet Explorer is automatable. You can use [this sample code](http://msdn.microsoft.com/library/aa752127.aspx) to open an Internet Explorer window and navigate it to your *.mht file. All that's missing is calling `pBrowser2->Quit()` when you want to close the window. – Raymond Chen Jul 30 '14 at 18:37

1 Answers1

1

Rather than specifying NULL as the application name, use c:\Program Files\Internet Explorer\iexplore.exe (or, your favorite browser). Then, pass the path of the .mht file as the command line parameter. To close the browser, you'll need to enumerate processes and post the appropriate message to the browser process.

rrirower
  • 4,338
  • 4
  • 27
  • 45