Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Detecting default web browser

Posted on 1998-08-18
7
Medium Priority
?
337 Views
Last Modified: 2010-04-04
How can I detect the default web browser from Delphi 3 applicatuion?
0
Comment
Question by:fh1
[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
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
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

730 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