Solved

knowing the default browser

Posted on 2002-06-13
10
271 Views
Last Modified: 2010-04-04
knowing whats the default browser in my system
exe. this will return the file and the file location
 c:\program files\IEXPLORER\iexplorer.exe
0
Comment
Question by:girlswants_me
10 Comments
 

Author Comment

by:girlswants_me
ID: 7074863
anybody can help me, specially this one can detect on windows XP
0
 

Author Comment

by:girlswants_me
ID: 7074888
how will i identify what kind of browser is the default ON WINDOWS XP, NOTE: as a REGULAR USER in XP.
0
 
LVL 44

Expert Comment

by:bruintje
ID: 7074950
Hi, you could take a look at this article

http://community.borland.com/article/0,1410,26083,00.html

HAGD:O)Bruintje
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 14

Expert Comment

by:DragonSlayer
ID: 7074953
Or you can just open the registry and have a look at

HKEY_CLASSES_ROOT\http\shell\open\command
0
 
LVL 22

Accepted Solution

by:
Mohammed Nasman earned 100 total points
ID: 7075011
Hello

  use the FindExecutable API
0
 
LVL 2

Expert Comment

by:Tasomia
ID: 7075086
Hi,

Two solutions:

1)

type
  TBrowserInformation = record
    Name: string;
    Path: string;
    Version: string;
  end;

function LongPathName(ShortPathName: string): string;
var
  PIDL: PItemIDList;
  Desktop: IShellFolder;
  WidePathName: WideString;
  AnsiPathName: AnsiString;
begin
  Result := ShortPathName;
  if Succeeded(SHGetDesktopFolder(Desktop)) then
  begin
    WidePathName := ShortPathName;
    if Succeeded(Desktop.ParseDisplayName(0, nil, PWideChar(WidePathName),
      ULONG(nil^), PIDL, ULONG(nil^))) then

      try
        SetLength(AnsiPathName, MAX_PATH);
        SHGetPathFromIDList(PIDL, PChar(AnsiPathName));
        Result := PChar(AnsiPathName);

      finally
        CoTaskMemFree(PIDL);
      end;
  end;
end;

function GetDefaultBrowser: TBrowserInformation;
var
  tmp: PChar;
  res: LPTSTR;
  Version: Pointer;
  VersionInformation: Pointer;
  VersionInformationSize: Integer;
  Dummy: DWORD;
begin
  tmp := StrAlloc(255);
  res := StrAlloc(255);
  Version := nil;
  try
    GetTempPath(255, tmp);
    if FileCreate(tmp + 'htmpl.htm') <> -1 then
    begin
      if FindExecutable('htmpl.htm', tmp, res) > 32 then
      begin
        Result.Name := ExtractFileName(res);
        Result.Path := LongPathName(ExtractFilePath(res));
        // Try to determine the Browser Version
        VersionInformationSize := GetFileVersionInfoSize(Res, Dummy);
        if VersionInformationSize > 0 then
        begin
          GetMem(VersionInformation, VersionInformationSize);
          GetFileVersionInfo(Res, 0, VersionInformationSize, VersionInformation);
          VerQueryValue(VersionInformation, ('StringFileInfo040904E4ProductVersion'),
            Pointer(Version), Dummy);
          if Version <> nil then
            Result.Version := PChar(Version);
          FreeMem(VersionInformation);
        end;
      end
      else
        ShowMessage('Can''t determine the executable.');
      SysUtils.DeleteFile(tmp + 'htmpl.htm');
    end
    else
      ShowMessage('Can''t create temporary file.');
  finally
    StrDispose(tmp);
    StrDispose(res);
  end;
end;

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


2)


procedure TForm1.Button1Click(Sender: TObject);
var
  Reg: TRegistry;
  KeyName: string;
  ValueStr: string;
begin
  Reg := TRegistry.Create;
  try
    Reg.RootKey := HKEY_CLASSES_ROOT;
    KeyName  := 'htmlfile\shell\open\command';
    if Reg.OpenKey(KeyName, False) then
    begin
      ValueStr := Reg.ReadString('');
      Reg.CloseKey;
      Label1.Caption := ValueStr;
    end
    else
      ShowMessage('No Default Webbrowser !');
  finally
    Reg.Free;
  end;
end;


0
 
LVL 3

Expert Comment

by:raidos
ID: 7075140
Tasomia, note that your 2nd solution doesn't really work...

Applications should read .html\ first to get what Key to read the correct browser application...htmlfile is not used by for instance Opera...

something like this..

Function GetDefaultBrowser: String;
Var
  Reg : TRegistry;
  Browser : String;
Begin
  Result := '';
  Reg := TRegistry.Create;
  Reg.RootKey := HKEY_CLASSES_ROOT;
  If Reg.OpenKeyReadOnly('\.html') Then Begin
    Browser := Reg.ReadString('');
    Reg.CloseKey;
    If (Browser <> '') And Reg.OpenKeyReadOnly(Format('\%s\shell\open\command', [Browser])) Then Begin
      Result := Reg.ReadString('');
      If Result[1] = '"' Then Begin
        Result := Copy(Result, 2, Length(Result)-1);
        Result := Copy(Result, 1, Pos('"', Result)-1);
      End;
    End;
  End;
  Reg.CloseKey;
  Reg.Free;
End;

Regards
//raidos
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 7075171
TESTED UNDER XP PRO :

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs,Registry, StdCtrls;

const
  DEF_BROWSER = 'No Default Web Browser';


type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    function GetDefBrowser: String;
    function GetBrowserPath(AValue: String): String;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function TForm1.GetDefBrowser: String;
var
  Reg : TRegistry;
begin
  Result := '';
  Reg    := TRegistry.Create;
  try
    Reg.RootKey := HKEY_CLASSES_ROOT;
    if Reg.OpenKey('\http\shell\open\command',FALSE) then
      // '' checks the default value
      if Reg.ValueExists('') then
        // '' reads the default value
        Result := Reg.ReadString('');
    Reg.CloseKey;
  finally
    Reg.Free;
  end;
end;

function TForm1.GetBrowserPath(AValue: String): String;
var
  x      : Integer;
  tmpStr : String;
begin
  Result := DEF_BROWSER;
  if AValue = '' then
    Exit;
  // Delph strings start at 1 but we need to start past the first
  // set of quotes in the default value of the command registry
  for x := 2 to Length(AValue) do
  begin
    if AValue[x] = '"' then
      Break;
    tmpStr := tmpStr + AValue[x];
  end;

  Result := tmpStr;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  tmpStr : String;
begin
  tmpStr := GetDefBrowser();
  tmpStr := GetBrowserPath(tmpStr);
  ShowMessage(tmpStr);

end;

end.
0
 

Author Comment

by:girlswants_me
ID: 7076900
thank you everybody. well some of your code dont work on WINDOWS XP, for an ORDINARY USER. an ordinary user as you know is that the one who cannot write or read some files in the windows xp system or some directory. some other registry access are disallowed or cant be access.

So ill just used this code.. coz i already have an HTML file installed in the machine(this installed file was installed by a SUPER USER OR the Administrator which has the full access of the operating system.) when some other ORDINARY USER LOGGED in the system the user rights also change so some other userfull or important registry informations are change.

so i used this code instead

  FindExecutable(Pchar(THE_HTML_FILE),nil,Ret);
  sDefaultBrowserPath:= ExtractFilePath(Ret);
  sDefaultBrowserName:= ExtractFileName(Ret);
0
 

Author Comment

by:girlswants_me
ID: 7076903
THANK for your idea.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PDF library for Delphi 2 121
LAN or WAN ? 11 90
Is anyone willing to have a look through this code and help debug? 25 74
How to load 2 images in same column in Delphi 2 46
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

776 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