Solved

knowing the default browser

Posted on 2002-06-13
10
269 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

920 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now