以前写过这个东西:http://bbs.bathome.net/thread-30886-1-1.html,把关键部分提取出来,存为 listcom.js,运行即可得到本机可用的com组件.txt- var fso = new ActiveXObject('Scripting.FileSystemObject')
- var ts = fso.CreateTextFile('本机可用的com组件.txt',true)
- ts.Write(listcom().join('\r\n'))
-
-
- function listcom(){
- //列举本机所有的 com 组件
- //主要代码修改自 http://hi.baidu.com/badguest/item/b091cc5b61b99c14db163563
- var retArr=[]
- var ws = new ActiveXObject('WScript.Shell')
- var dict = new ActiveXObject('Scripting.Dictionary')
- var oLoc=new ActiveXObject("WbemScripting.SWbemLocator")
-
- var HKCR=0x80000000
-
- var oReg=oLoc.ConnectServer(null,"root\\default").Get("StdRegProv")
- var oMethod=oReg.Methods_("EnumKey")
- var oInParam=oMethod.InParameters.SpawnInstance_()
- oInParam.hDefKey=HKCR
- oInParam.sSubKeyName=''
- var NameAndType=oReg.ExecMethod_(oMethod.Name,oInParam)
- var arrSubKeys=NameAndType.sNames.toArray()
-
- //~列举HKEY_CLASSES_ROOT中所有键
- for(var i=0;i<arrSubKeys.length;i++){
- var key=arrSubKeys[i]
- if(key.search(/..\./)<0)continue
- if(key.search(/..\..*\./)>0){
- /*~there's a dot. Is there another one?
- yes, so this name is version specific
- check whether we already have a
- version-independent progid! */
- independent = key.replace(/.+?$/,'')
- if (!dict.Exists(independent)){
- //~no, store it
- dict.Add(key, 0)
- }
- }else{
- /*~this one is version-independent.
- do we already have a version-dependent
- progID in store?*/
- var vdpid = ""
-
- for(var element in dict){
- if (element.length>key.length){
- if (element.substring(key.length)==key + "."){
- //~yes, return name
- vdpid = element
- break
- }
- }
- }
-
- //~any version dependent progID found?
- if (vdpid.length) {
- //~yes, replace
- dict.Remove(vdpid)
- dict.Add(key, '')
- }else{
- //~no, add to store
- dict.Add(key, '')
- }
- }
- }
- var arr = new VBArray(dict.Keys()).toArray();
- for (var i=0;i<arr.length;i++){
- retArr.push(arr[i])
- }
- return retArr
- }
复制代码
|