Solved

knowing the default browser

Posted on 2002-06-13
10
268 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
Comment Utility
anybody can help me, specially this one can detect on windows XP
0
 

Author Comment

by:girlswants_me
Comment Utility
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
Comment Utility
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
Comment Utility
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:
mnasman earned 100 total points
Comment Utility
Hello

  use the FindExecutable API
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 2

Expert Comment

by:Tasomia
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
THANK for your idea.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now