views:

362

answers:

2

Is there a way to test if an ActiveX control is installed using Javascript?

+3  A: 
function AXOrNull(progId) {
  try {
    return new ActiveXObject(progId);
  }
  catch (ex) {
    return null;
  }
}
Tomalak
Well, I thought this was working, but the ActiveX files are now on my local machine, and this method always returns null.I was given this code:<object id="ASPPrinter" classid="CLSID:48CB850F-41FF-4EE6-B87D-FB9EC26D193F" codebase="ASPPrinter.CAB#version=2,1,0,200"> </object>but I'm not sure which part of that code should go in for progId. I tried it with the classid from that code and the codebase, both of them always return null.
Pselus
When in doubt, search through the `HKCR\CLSID` branch of the registry for the CLSID in question. When you've found it *and* the class is COM enabled, you'll find a sub-key named `ProgID`. The default value of that key is the ProgID you need.
Tomalak
AXOrNull('ASPPrinter.CAB')
drlouie - louierd
I tried 'ASPPrinter.CAB', didn't work. Then I looked in the registry like Tomalak said, and there is no item with that CLSID. Which means that it isn't installed...but IE is no longer prompting me to install them...so I'm not sure what's happened.
Pselus
@Pselus: Have you tried `ASPPrinterCOM.ASPPrinter`? This seems to be the right ProgId according to some Google result.
Tomalak
+1  A: 

Solution, try to invoke a new ActiveXObject:


function testForActiveX(){
    tester = null;
    try {
        tester = new ActiveXObject('htmlfile');
    }
     catch (e) {
        // catch the exception
    }
    if (tester) {
        // ActiveX is installed
        return true;
    }
    return false;
}
drlouie - louierd