?
Solved

Launch default web browser to open HTML file

Posted on 2002-06-06
5
Medium Priority
?
310 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 400 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

762 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