Dor Cohen
Dor Cohen

Reputation: 17090

Create ActiveXObject from GUID

I have the following line in my code:

var ScreenRecorder = new ActiveXObject('CCScreenRecorder.ScreenRecorder');

The problem is that I have 2 entries of this
(one for each version, don't ask me why - this is a fact I need to deal with),

So I want to create the ActiveXObject from the GUID.

I tried to do:

document.createElement('<OBJ' + 'ECT ID="ScreenRecorderWrapper" CLA' + 'SSID="CL' + 'SID:37CCF998-3BB7-' + '4F8A-9D9F-EF391543E94A"></OB' + 'JECT>');
var ScreenRecorder = ScreenRecorderWrapper;

but the problem is that ScreenRecorderWrapper will be defined only after SetTimeout or some other manipulation.

Can I get the ActiveXObject from it's GUID and not from it's name?
Something like:

var ScreenRecorder = new ActiveXObject('37CCF668-3BB7-4F8A-9D9F-EF391543E94A');

Upvotes: 1

Views: 8750

Answers (2)

manuell
manuell

Reputation: 7620

Use the registry for obtaining the ProgId from the CLSID. Reading the registry in JS is possible through the "Shell" ActiveX

var shellObj = new ActiveXObject("WScript.Shell");
var clsid = "37CCF668-3BB7-4F8A-9D9F-EF391543E94A";
var progid = shellObj.RegRead("HKEY_CLASSES_ROOT\\CLSID\\{"+clsid+"}\\ProgID\\");
var ScreenRecorder = new ActiveXObject( progid );

Upvotes: 0

Eric Brown
Eric Brown

Reputation: 13942

ActiveXObject requires a ProgID, however, you can use a version-dependent ProgID rather than a version-independent ProgID.

Version-dependent ProgIDs typically have a version number appended to the version-independent ProgID.

In this case, the version-independent ProgID is 'CCScreenRecorder.ScreenRecorder', and the version-dependent ProgID would be something like 'CCScreenRecorder.ScreenRecorder.1' or 'CCScreenRecorder.ScreenRecorder.2'.

Note that using a version-dependent ProgID can fail if the wrong version is installed. You might want to try the version-dependent ProgID first, and fall back to the version-independent ProgID.

Upvotes: 0

Related Questions