Solved

Launch default web browser to open HTML file

Posted on 2002-06-06
5
307 Views
Last Modified: 2013-11-20
I want to programmatically launch the default web browser to open an HTML file, but I can't get it to work.  I am trying to do it by calling CreateProcess and passing it the command:

start "" /I "File Path.html"

This works when I type it on the command line, but not when I use CreateProcess.  CreateProcess() returns FALSE and GetLastError() returns 123 (The filename, directory name, or volume label syntax is incorrect.)

I see that start is not a real executable, so I tried it with cmd.exe like this:

cmd.exe /c start "" /I "File Path.html"

with the same results, so I tried it with the full path, like this:

c:\windows\system32\cmd.exe /c start "" /I "File Path.html"

but still I get the same result.  Here is my code snippet, what should I do to accomplish this task?

--------------------------


//CString sFilePath is defined before this point
//it is an output file of another operation
//I am confident that the file path is correct and complete
//open the output file using the default web browser
//by executing:
//cmd.exe /C start "" /I "FilePath"
CString sFullCommandLine;
//TODOLATER: read the appropriate path from the registry
CString sCmdExePath = "c:\\windows\\system32\\cmd.exe";
sFullCommandLine.Format("%s /C start \"\" /I \"%s\"", sCmdExePath, sFilePath);

PROCESS_INFORMATION ProcessInfo = {0,0,0,0}; //receives info about the launched process

STARTUPINFO StartupInfo; //specifies window creation info for CreateProcess()
StartupInfo.cb          = sizeof(STARTUPINFO);
StartupInfo.lpReserved  = NULL;
StartupInfo.lpDesktop   = NULL;
StartupInfo.lpTitle     = NULL;
StartupInfo.cbReserved2 = NULL;
StartupInfo.lpReserved2 = NULL;
StartupInfo.dwFlags     = NULL;

BOOL bSuccess = CreateProcess(
    sFullCommandLine,   //App Name
    NULL,               //command line
    NULL,               //security attributes
    NULL,               //thread attributes
    TRUE,               //inherit handles,
    NULL,               //creation flags
    NULL,               //environment
    NULL,               //working directory
    &StartupInfo,       //startup info
    &ProcessInfo);      //lpProcessInformation
0
Comment
Question by:ris
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
5 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 100 total points
ID: 7060430
Why don't you just use

ShellExecute ( NULL, "open", "c:\\mypath\\myfile.htm", NULL, NULL, SW_SHOWNORMAL);

?
0
 
LVL 86

Expert Comment

by:jkr
ID: 7060433
BTW, "ShellExecute()" always launches the application that is registered for the file type, just as if you would double-click on it.
0
 
LVL 86

Expert Comment

by:jkr
ID: 7063228
Is anything unclear about this?
0
 
LVL 1

Author Comment

by:ris
ID: 7063311
Thanks, that's exactly the solution I was looking for.  I haven't had a chance to test it yet, but I expect it to work.
0
 
LVL 86

Expert Comment

by:jkr
ID: 7063760
Oh, I am sure that it will work :o)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question