Solved

How to detect if internet and a browser is installed?

Posted on 1998-06-19
5
186 Views
Last Modified: 2010-04-04
I write at a program in Delphi 3 that will use a TLABEL as link to a website. It gets the ONCLICK-Event and should start the browser with the URL defined in .CAPTION. I know that IE4 can connect to an URL given thru the command line as parameter. But first, how would i check, if IE or NS or any other browser and a internet-access software is installed on the computer that runs my program on :)

thx, Omsec
0
Comment
Question by:omsec
5 Comments
 
LVL 10

Expert Comment

by:Jacco
ID: 1354100
You can try

ShellExecute('http:\\www.microsoft.com');

this way you execute a URL

Internet explorer is started automatically

No command line needed.

To determine wether IE is installed you can check the proper registryentries !
0
 
LVL 2

Author Comment

by:omsec
ID: 1354101
do I have to include a special (Active-X) Control/Unit ?
0
 

Expert Comment

by:dskowron
ID: 1354102
Delphi 3 includes native controls for web programming so there would be no need for any Active X or other outside control. However, the comment made by Jacco is correct - you just execute the url. The "HTM" or "HTML" file extension would be registered to be handled by the user's browser. If none existed, you could trap that error. Actually, in that case, you could launch a simple browser that you write in Delphi 3.
0
 
LVL 2

Author Comment

by:omsec
ID: 1354103
ShellExecute('http:\\www.microsoft.com'); does not work
0
 
LVL 6

Accepted Solution

by:
Holger101497 earned 50 total points
ID: 1354104
I'm afraid it is a little more complicated than this....
Try to take a look at the Delphi FAQ at http://www.inprise.com/devsupport/delphi/qanda/#9

This is for How to launch web site in default browser:

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;

I've used it and it works... I now just saw this other FAQ:
Launching a web browser

                       Question:

                       How can I launch the computer's current web brower with a specific web site URL?

                       Answer:

                       Call the Win32 API function called HlinkNavigateString which is
                       declared in the UrlMon unit.

                       Example call:

                         HlinkNavigateString(Nil,'http://www.borland.com');

                       If you're calling this from an ActiveForm then call it like this:

                         HlinkNavigateString(ComObject,'http://www.borland.com');

Seems a lot simpler, but I don't know exactly what it does. Also, the first example gives you a lot more information...
Good luck!!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

758 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

22 Experts available now in Live!

Get 1:1 Help Now