Solved

How to detect if internet and a browser is installed?

Posted on 1998-06-19
5
188 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

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
Sending Gmail through Delphi 3 106
How to fill array with TArray.Create? 14 87
error 1.1 400 Bad request idhttp delphi 18 86
Delphi Form ownership 4 87
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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 Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

785 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