Detecting Plugins in Internet Explorer

You want visitors to your website to view its media in the way intended. If you website is particularly media rich, you will want them to be able to check whether they have the appropriate plug-ins installed in their browsers. Internet Explorer, still the browser of choice for most Internet users, makes this task a little difficult — but with some VBScript code, you can put together a basic Web page that gets the job done.

With so many media rich technologies in use on the Internet today, a designer’s hardest task can often be deciding which of these technologies to use. Do you present your text as plain text on the page, in a PDF format perhaps, or something proprietary such as Microsoft Word? Do you present your graphics as flat pictures, animated GIFs or super smooth Flash movies? 

The answers, no doubt, will depend on many things, including the resources you have at hand, the time frame you are working to, and most importantly, your target audience. Additionally, your site will probably have any, all or a combination of presentation media present.  Deciding to invest time, effort and money into a presentation solution such as Flash will undoubtedly improve the appearance of any website — for those people lucky enough to have an appropriate viewer, and this is something that many Internet users wouldn’t know. For example, my old man is on the Internet almost as much as I am, but if I asked him which version of Flash he had, he’d probably think I was alluding to the original black and white films or the 1980’s cult classic. 

As for knowing which version of the player people have installed, forget it!  Even in a completely controlled, managed desktop environment, it is sometimes hard to tell which version of a specific plug-in people will have in their browsers when accessing say, the company intranet.

A mechanism is needed to address this issue and there are two common ways of approaching it. You can implement a script on the page containing the flash movie, or real clip or whatever media, that tests the browser for which plug-ins are installed and then either plays the active multimedia content if the appropriate plug-in is available or redirects the visitor to a page where the plug-in can be downloaded if it is not present. Or you can simply have a page separate from the page that makes use of the plug-ins, which tests the browser and outputs a report advising which plug-ins are available and whether any action needs to be taken prior to accessing the pages containing the active content. 

Both options have their good and bad points. The first option is more helpful, automatically taking the appropriate action based upon the needs of the visitor; however, this would possibly interrupt the logical flow of the user’s browsing experience, taking them to an external site that they may not wish to visit. The second example, while informative, does nothing to counter the problem if the user does not have the object required. Nevertheless, some kind of solution needs to be introduced if you want to run media rich files on your website, and some kind of test will need to be performed on visitors’ browsers to advise them if they do not have the plug-in needed.

{mospagebreak title=How Navigator Handles the Problem}   

Netscape Navigator tackles this problem by using an array built directly into the browser object, called simply plugin (navigator.plugins), that lists all of the plug-ins installed in the browser. This array can then be accessed quickly and efficiently through the use of the ever-popular scripting language JavaScript, provided version 1.1 or above is supported. A simple document that makes use of the .plugins property can be put together as follows:

<html>

<head>

<title>Netscape Plugin Detection</title>

</head>

<body>

<h1>The plugins you have installed are:</h1>

<script language=’JavaScript’>

  if (navigator.plugins){

    for (i=0; i < navigator.plugins.length; i++){

    document.writeln(“Plugin Name: ” + navigator.plugins[i].name + “<br>”);

    }

  }

</script>

</body>

It is messy, in part because some of the plug-ins are listed more than once, but it works with a minimal amount of effort. The plugins array has some additional properties such as .filename and .description, which provide, yes, you’ve guess it, information on the filename of the plug-in, and a brief description of the plug-in, such as:

Plugin Filename: npswf32.dll
Plugin Description: Shockwave Flash 7.0 r19
    

{mospagebreak title=IE’s Approach}

Unfortunately, Microsoft’s Internet Explorer is not quite as helpful; the browser itself has no plugins array (and doesn’t actually support plug-ins) so JavaScript cannot be employed quickly and easily to provide a report of any installed plug-ins. ActiveX objects (often called activeX controls) are implemented in Explorer in much the same way as plug-ins; however, it should be noted that they are separate things. Makers of plug-ins will have to produce separate activeX objects for use specifically in IE. 

One of the things plug-in makers need to do when creating their activeX objects is to assign these objects a unique value known as the CLSID or classid.  One of the ways in which we can test the browser for installed objects is through the use of this CLSID value, which is different for all activeX objects. Some differing versions of the same activeX object will have the same CLSID value, however; Windows Media Player 7 and 8 are an example of this, which have a CLSID of {6BF52A52-394A-11D3-B153-00C04F79FAA6}. You can find this value and others in the Windows registry using RegEdit or a similar tool.

Another value that these objects will has is the progID; again, these strings are unique to the object they represent, but different versions of the same object may share the same progID, and the versions that a progID refer to may not be logical. For example, the progID for Shockwave Player version 6 is SWCtl.SWCtl.1, whereas the progID for version 7 is SWCtl.SWCtl.7 which makes detecting player versions prior to version 6 somewhat difficult. In reality however, it is unlikely that many people have a version this old installed on their systems. 

In truth, you could probably get away with writing an expression that tested for versions 8, 7, 6 or less than 6, rather than testing for every single version. This is just an example however; Shockwave Player is now at version 10, and tests for this will be worked into our object tester. Another thing to watch for is that applications may suddenly change their progID values between versions for no logical reason; Adobe’s Acrobat Reader version 6 has a progID of PDF.PdfCtrl.6, whereas Acrobat Reader version 7 has the progID AcroPDF.PDF.1 which again, can make things tricky if you don’t arm yourself with the correct information each time a new version of the plug-in is released.

You could, of course, have a page on your site that had embedded files of all major plug-ins on it, and some text below each one that says something like: if this file fails to play, you do not have an appropriate player/plug-in installed.  But frankly, this is rubbish.

{mospagebreak title=Getting started}

Detecting plug-ins in IE is not actually that difficult; ideally, you need to use VBScript. In fact, even if you use JavaScript, you still have to get the script to write the VBScript code, so for now we’ll cut out the middle-man and stick with the proprietary script language. Since you’re targeting Microsoft Internet Explorer users only with the script, it will work. Please note that this article is not an article discussing cross-browser interoperability; I’m assuming that you already have a half-decent browser vendor detection and redirection or similar system.  This script will only work on MSIE browsers (ideally version 6)!

It should be noted at this point also that it is not possible to detect these kinds of things using PHP, because of the way that server-side scripting works; the page is created before it is passed to the browser, so there is no way for the script on the server to get this kind of information until after the page has been created, and by then, it’s too late.

So, to begin, get yourself a basic HTML page set up; we’re not worried about presentation at this stage, so the following will do:

<html>

<head>

<title>MSIE Plug-in Detection</title>

</head>

<body>

<h1>Welcome to the Plug-in Detection Page</h1>

</body>

</html>

The script is fairly long and fairly repetitive, but it is very basic considering and is easy enough to follow.  Yes, there are better ways of doing it to reduce the amount of code, but again, this is not an article discussing clean and efficient code, it’s about writing a script that has a specific purpose and works.

Set the script tags in the body of the document and begin by adding the on error resume next statement:

<script type=”text/vbscript”>

on error resume next

The script will not work without this statement.  Next, you can declare all of your variables, using the Dim statement followed by the name of each variable, but as we are including some version checking where possible, there are rather a lot of them and the script is long enough as it is. We’ll leave them out because, fortunately, variables do not have to be explicitly declared in VBScript. 

{mospagebreak title=The heart of plug-in detection}

What we’ll do instead is get to the heart of the plug-in detection.  It is done by trying to create an instance of each activeX control. If it works, the value true is passed back to the variable; if not, then the value false is passed back:

checkForAcroRead7 = (IsObject(CreateObject(“acroPDF.PDF.1″)))

checkForAcroRead6 = (IsObject(CreateObject(“PDF.PdfCtrl.6″)))

checkForAcroRead5 = (IsObject(CreateObject(“PDF.PdfCtrl.5″)))

checkForAcroRead4 = (IsObject(CreateObject(“PDF.PdfCtrl.4″)))

checkForAcroRead3 = (IsObject(CreateObject(“PDF.PdfCtrl.1″)))

checkForFlash7 = (IsObject(CreateObject(“ShockwaveFlash.ShockwaveFlash.7″)))

checkforFlash6 = (IsObject(CreateObject(“ShockwaveFlash.ShockwaveFlash.6″)))

checkforFlash5 = (IsObject(CreateObject(“ShockwaveFlash.ShockwaveFlash.5″)))

checkForFlash4 = (IsObject(CreateObject(“ShockwaveFlash.ShockwaveFlash.4″)))

checkForFlash3 = (IsObject(CreateObject(“ShockwaveFlash.ShockwaveFlash.3″)))

checkForQT6 = (IsObject(CreateObject(“QuickTime.QuickTime.4″)))

checkForQT5 = (IsObject(CreateObject(“QuickTimeCheckObject.QuickTimeCheck.1″)))

checkForReal = (IsObject(CreateObject(“rmocx.RealPlayer G2 Control.1″)))

checkForSW10 = (IsObject(CreateObject(“ShockwaveFlash.ShockwaveFlash.1″)))

checkForSW9 = (IsObject(CreateObject(“SWCt1.SWCt1.9″)))

checkForSW8 = (IsObject(CreateObject(“SWCt1.SWCt1.8″)))

checkForSW7 = (IsObject(CreateObject(“SWCt1.SWCt1.7″)))

checkForSW6 = (IsObject(CreateObject(“SWCt1.SWCt1.1″)))

checkForWMP = (IsObject(CreateObject(“MediaPlayer.MediaPlayer.1″)))

Where possible, we are checking for versions as well as whether the plug-in exists at all. 

{mospagebreak title=Displaying the results}

Now comes the part where we display the results of these tests to the user:

if checkForAcroRead7 = true then

  document.write(“<br><b>You have Adobe Acrobat Reader version 7 installed.</b>”)

elseIf checkForAcroRead6 = true then

  document.write(“<br><b>You have Adobe Acrobat Reader version 6 installed.</b>”)

elseIf checkForAcroRead5 = true then

  document.write(“<br><b>You have Adobe Acrobat Reader version 5 installed.</b>”)

elseIf checkForAcroRead4 = true then

  document.write(“<br><b>You have Adobe Acrobat Reader version 4 installed.</b>”)

elseIf checkForAcroRead3 = true then

  document.write(“<br><b>You have Adobe Acrobat Reader version 3 installed.</b>”)

else

  document.write(“<br><b>You do not have Adobe Acrobat Reader installed</b>”)

end if

if checkForFlash7 = true then

  document.write(“<br><b>You have Flash Player 7 installed.</b>”)

elseIf checkForFlash6 = true then

  document.write(“<br><b>You have Flash Player 6 installed.</b>”)

elseIf checkForFlash5 = true then

  document.write(“<br><b>You have Flash Player 5 installed.</b>”)

elseIf checkForFlash4 = true then

  document.write(“<br><b>You have Flash Player 4 installed.</b>”)

elseIf checkForFlash3 = true then

  document.write(“<br><b>You have Flash Player 3 installed.</b>”)

else

  document.write(“<br><b>You do not have Flash Player Installed.</b>”)

end if

if checkForQT6 = true then

  document.write(“<br><b>You have Quicktime Player 6 installed.</b>”)

elseIf checkForQT5 = true then

  document.write(“<br><b>You have Quicktime Player 5 installed.</b>”)

else

  document.write(“<br><b>You do not have Quicktime installed.</b>”)

end if

if checkForReal = true then

  document.writeln(“<br><b>You have Real Player installed.</b>”)

else

  document.write(“<br><b>You do not have Real Player installed.</b>”)

end if

if checkForSW10 = true then

  document.write(“<br><b>You have Shockwave Player 10 installed.</b>”)

elseif checkForSW9 = true then

  document.write(“<br><b>You have Shockwave Player 9 installed.</b>”)

elseif checkForSW8 = true then

  document.write(“<br><b>You have Shockwave Player 8 installed.</b>”)

elseif checkForSW7 = true then

  document.write(“<br><b>You have Shockwave Player 7 installed.</b>”)

elseif checkForSW6 = true then

  document.write(“<br><b>You have Shockwave Player 6 installed.</b>”)

else

  document.write(“<br><b>You do not have Shockwave Player installed.</b>”)

end if

if checkForWMP = true then

  document.write(“<br><b>You have Windows Media Player installed.</b>”)

else

  document.write(“<br><b>You do not have Windows Media installed.</b>”)

end if

Now you just close off the script:

</script>

And save the page as pluginChecker.htm. Open it in MSIE and see for yourself which versions of which plug-ins you have installed. Windows XP Service Pack 2 users will get the infobar blocking the active content, so good practice dictates that instructions for handling this should be placed on any publicly viewed pages.

{mospagebreak title=Extending the Script} 

We can extend this script further and check for other applications installed on the client computer:

checkForExcel = (IsObject(CreateObject(“Excel.Application”)))

checkForWord = (IsObject(CreateObject(“Word.Application”)))

checkForPowpoint = (IsObject(CreateObject(“Powerpoint.Application”)))

checkForAccess = (IsObject(CreateObject(“Access.Application”)))

if checkForExcel = true then

  document.write(“<br><b>You have Microsoft Excel Installed.</b>”)

else

  document.write(“<br><b>You do not have Microsoft Excel Installed.</b>”)

end if

if checkForWord = true then

  document.write(“<br><b>You have Microsoft Word Installed.</b>”)

else

  document.write(“<br><b>You do not have Microsoft Word Installed.</b>”)

end if

if checkForPowpoint = true then

  document.write(“<br><b>You have Microsoft Powerpoint Installed.</b>”)

else

  document.write(“<br><b>You do not have Microsoft Powerpoint Installed.</b>”)

end if

if checkForAccess = true then

  document.write(“<br><b>You have Microsoft Access Installed.</b>”)

else

  document.write(“<br><b>You do not have Microsoft Access Installed.</b>”)

end if

 

Or even:

checkForPhotoshop = (IsObject(CreateObject(“Photoshop.Application”)))

if checkForPhotoshop = true then

  document.write(“<br><b>You have Adobe Photoshop Installed.</b>”)

else

  document.write(“<br><b>You do not have Adobe Photoshop Installed.</b>”)

end if  

In addition to the infobar warning, unfortunately, users will also get a nasty yes/no box about unsafe activeX controls, which will probably just make visitors leave your site very quickly.

Now, the page is not pretty. It’s cold, and it’s basic. If pressed, you could probably get VBScript to draw a table and insert the results of each test into that, along with a pretty little logo of the plug-in and a button linking to the plug-in vendor’s site that would be invisible if the plug-in was installed, but visible if it was not. Of course, that would be another article in itself.  

4 thoughts on “Detecting Plugins in Internet Explorer

  1. Thanks for the article. Its a big help, confirmed my suspicions that yet again IE is a bit of a letdown! Fancy having a plugins[] array, but one that is always empty, a thus useless.

  2. createObject(“Word.Application”) will actually fire up WINWORD.EXE in the background, and there is no way that you can shutdown that process from the script. You have to eventually kill that process from the Task Manager. (The object.Quit method won’t shutdown the process either).

    Cheers,

    Allan Nguyen

[gp-comments width="770" linklove="off" ]