Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Detecting default web browser

Posted on 1998-08-18
7
Medium Priority
?
338 Views
Last Modified: 2010-04-04
How can I detect the default web browser from Delphi 3 applicatuion?
0
Comment
Question by:fh1
7 Comments
 
LVL 8

Expert Comment

by:ZifNab
ID: 1337193
fh1,

is it for just starting the default browser?

Then use this :

ShellExecute(Self.Handle,'open','http://www.attitudesoft.com.au/news.htm','','',
SW_SHOWDEFAULT);

Regards, Zif.
0
 
LVL 8

Accepted Solution

by:
ZifNab earned 150 total points
ID: 1337194
And here is an answer to your question, from TI
Frequently Asked Questions
Displaying documents in the default browser
Question:
How can I start the default browser with an URL in a new browser window?
Answer:
The following example attempts to start the specified URL
in a new browser window. Note: Not all versions of
Internet Explorer will respond with a new window.

Example:

uses
 DdeMan,
{$IFDEF WIN32}
  Registry; {We will get it from the registry}
{$ELSE}
  IniFiles; {We will get it from the win.ini file}
{$ENDIF}

{$IFNDEF WIN32}
  const MAX_PATH = 144;
{$ENDIF}

function GetProgramAssociation (Ext : string) : string;
var
{$IFDEF WIN32}
  reg: TRegistry;
  s : string;
{$ELSE}
  WinIni : TIniFile;
  WinIniFileName : array[0..MAX_PATH] of char;
  s : string;
{$ENDIF}
begin
{$IFDEF WIN32}
  s := '';
  reg := TRegistry.Create;
  reg.RootKey := HKEY_CLASSES_ROOT;
  if reg.OpenKey('.' + ext + '\shell\open\command',
                 false) <> false then begin
  {The open command has been found}
    s := reg.ReadString('');
    reg.CloseKey;
  end else begin
  {perhaps thier is a system file pointer}
    if reg.OpenKey('.' + ext,
                   false) <> false then begin
      s := reg.ReadString('');
      reg.CloseKey;
      if s <> '' then begin
     {A system file pointer was found}
        if reg.OpenKey(s + '\shell\open\command',
                       false) <> false then
     {The open command has been found}
          s := reg.ReadString('');
        reg.CloseKey;
      end;
    end;
  end;
 {Delete any command line, quotes and spaces}
  if Pos('%', s) > 0 then
    Delete(s, Pos('%', s), length(s));
  if ((length(s) > 0) and
      (s[1] = '"')) then
    Delete(s, 1, 1);
  if ((length(s) > 0) and
      (pos('"', s) > 0)) then
    Delete(s, pos('"', s), Length(s));
  while ((length(s) > 0) and
         (s[length(s)] = #32)) do
    Delete(s, Length(s), 1);
{$ELSE}
  GetWindowsDirectory(WinIniFileName, sizeof(WinIniFileName));
  StrCat(WinIniFileName, '\win.ini');
  WinIni := TIniFile.Create(WinIniFileName);
  s := WinIni.ReadString('Extensions',
                          ext,
                          '');
  WinIni.Free;
 {Delete any command line}
  if Pos(' ^', s) > 0 then
    Delete(s, Pos(' ^', s), length(s));
 {$ENDIF}
  result := s;
end;

procedure StartNewBrowserWindow(URL : string);
var
  DDEConv : TDDEClientConv;
  URLFired : bool;
  App : string;
  UpApp : string;
  p : array[0..MAX_PATH] of char;
begin
  UrlFired := false;
  App := GetProgramAssociation('HTM');
  UpApp := Uppercase(App);
  Delete(App, Pos('.EXE', UpAPP), length(App));
  if Pos('NETSCAPE.EXE',
         UpApp) > 0 then begin
    DDEConv:=TDDEClientConv.Create(nil);
    DDEConv.ServiceApplication := App;
    if DDEConv.SetLink('NETSCAPE' , 'WWW_OpenURL') then
      if DDEConv.RequestData(URL +
                             ',,0x0,0x0') <> nil then
        if DDEConv.SetLink('NETSCAPE', 'WWW_Activate') then
          URLFired := DDEConv.RequestData('0xFFFFFFFF,0x0') <> nil;
    DDEConv.Free;
  end else
  if Pos('IEXPLORE.EXE',
         UpApp) > 0 then begin
    DDEConv:=TDDEClientConv.Create(nil);
    DDEConv.ServiceApplication := App;
    if DDEConv.SetLink('iexplore', 'WWW_OpenURL') then
      if DDEConv.RequestData(URL + ',,0') <> nil then
        if DDEConv.SetLink('iexplore', 'WWW_Activate') then
          URLFired := DDEConv.RequestData('0,0') <> nil;
    DDEConv.Free;
  end;
  if UrlFired = false then
    WinExec(StrPCopy(@p, URL), SW_SHOWNORMAL);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  StartNewBrowserWindow('http://www.borland.com');
  StartNewBrowserWindow('http://www.yahoo.com');
end;

Regards, Zif.
0
 

Expert Comment

by:j_mollaghan
ID: 1337195
The simplest way to detect the default browser is to check the .HTML association from the registry. (look in HKEY_CLASSES_ROOT). You'll get (from the default value for .HTML) a class value for the browser (in my case it's value is NETSCAPEMARKEUP). Then, simply check the class for NETSCAPEMARKUP, note the CLSID for ii (a guid). Then check the information for the guid (still in HKEYCLASSESROOT), to get the path toe the browser. It only requires a few lines of code to get the path to the broswers EXE.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 4

Expert Comment

by:d003303
ID: 1337196
j_mollaghan,
this is the way ShellExecute does it:
- lookup for the value of HKEY_CLASSES_ROOT\.html (say it is NETSCAPEMARKEUP)
- lookup for the value of HKEY_CLASSES_ROOT\NETSCAPEMARKEUP\shell\open\command to get the command line.

Your solution describes the way OLE does it. OLE then checks for the HKEY_CLASSES_ROOT\CLSID\{61D8DE20-CA9A-11CE-9EA5-0080C82BE3B6} key and looks for InprocServer32, LocalServer32 and InprocHandler32. The values of these keys are then used for OLE Automation and OLE inplace activation/editing.
These values can differ between the values ShellExecute gets !

Slash/d003303
0
 

Author Comment

by:fh1
ID: 1337197
I am using ShellExecute, but if there is no web browser a window pops up and asks the user for the directory of the web browser. How can I prevent the window from showing up and instead show my own message?
0
 
LVL 4

Expert Comment

by:d003303
ID: 1337198
fh1,
two possibilities. One is to implement what ShellExecute does by yourself (bad), second is to check by yourself if a browser is installed. Use my comment above to check if the association exists, get the application filename and check if it exists. If yes, spawn ShellExecute. If no, pop up your message and don' spawn ShellExecute.

Slash/d003303
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1337199
fh1, don't know if it's possible with ShellExecute, but with ShellExecuteEx it is :

procedure TForm1.Button1Click(Sender: TObject);

var nHandle:integer;
    ShellInfo:TShellExecuteInfo;
    LastErrorMode : Uint;
begin
 FillChar(ShellInfo,Sizeof(ShellInfo), #0);
 ShellInfo.cbSize := Sizeof(ShellInfo);
 ShellInfo.Fmask := SEE_MASK_NOCLOSEPROCESS or SEE_MASK_FLAG_NO_UI {THIS ONE IS NEEDED FOR NO ERRORS!};
 ShellInfo.lpVerb := 'Open';
 ShellInfo.Wnd := Application.MainForm.Handle;

{Handles both EXE programs or Document Files}
 ShellInfo.lpFile := 'http://www.delphi.magsoft.com.pl';
 if not shellExecuteEx(@ShellInfo) then showmessage('error : '+IntToStr(ShellInfo.hInstApp));
 { if waiting till process is finished }
 WaitforSingleObject(ShellInfo.hProcess, INFINITE);
end;
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

927 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