打印和传真: ("winprint.winprintx") ("winfax.sdksend")? (faxserver.faxserver) ("fmfaxapi.application") ("oleprn.dsprintqueue.1")
数据库会话: ("accpac.xapisession")
报表与pdf发布: ("impromptu.application.30")
条形码与标签: ("bartender.application")
邮件群发: ("notes.notessession") ("notes.notesuiworkspace") ("notes.notesuiworkspace")
网络会议: ("netmeeting.app.1")
ms编程: ("msproject.application") ("sourcesafe.0")
路由与映射: ("mappoint.application")
矢量绘图: ("visio.application")
建模: ("rose.application")
再谈CreateObject函数,VBS到底能调用哪些对象?
VBS的CreateObject函数到底能够创建哪些对象,几乎是每个VBS新手都困惑的问题,他们总是热衷于寻找“VBS对象大全”。
对象的注册信息 HKEY_CLASSES_ROOTCLSID{GUID} 下可能会有这样的一些子键:Control 说明该组件是一个 ActiveX 控件、Programmable 说明该组件支持自动化、Insertable 说明该组件可以被嵌入到一个 OLE 文档容器中。能找到 Programmable,说明支持自动化,也就是支持 IDispatch 接口,所以它可以被脚本语言使用。不过这种方式比较老了,现在已经被一个的组件类属代替,即 Implemented Categories 子键下面的 GUID 形式的子键。比如 HKEY_CLASSES_ROOTCLSID{72C24DD5-D70A-438B-8A42-98424B88AFB8}Implemented Categories{40FC6ED5-2438-11CF-A3DB-080036F12502},看一下 HKEY_CLASSES_ROOTComponent Categories{40FC6ED5-2438-11CF-A3DB-080036F12502} 下的 409 字符串值为 Automation Objects,也就是“自动化对象”。
也就是说,如果注册表中一个对象的ProgID对应的CLSID下包含有子键Programmable或者Implemented Categories{40FC6ED5-2438-11CF-A3DB-080036F12502},那么这个对象就能用CreateObject函数创建。
假设上面的说法正确,那么我们可以用下面的脚本获取“VBS对象大全”:
| Option Explicit Const HKEY_CLASSES_ROOT = &H80000000 Dim arrProgID, strProgID, strCLSID Dim objReg, objFso, objFile, objShell Set objReg = GetObject("winmgmts:.rootdefault:StdRegProv") Set objFso = CreateObject("Scripting.FileSystemObject") Set objShell = CreateObject("WScript.Shell") Set objFile = objFso.OpenTextFile("ProgID.txt", 2, True) 'By Demon 'http://demon.tw objReg.EnumKey HKEY_CLASSES_ROOT, "", arrProgID For Each strProgID In arrProgID If GetCLSID(strProgID, strCLSID) Then If IsProgrammable(strCLSID) Or IsAutomationObject(strCLSID) Then objFile.WriteLine strProgID End If End If Next objShell.Run "ProgID.txt" Function RegKeyExists(hKey, strSubKey) Dim a, n n = objReg.EnumKey(hKey, strSubKey, a) If n = 0 Then RegKeyExists = True Else RegKeyExists = False End If End Function Function IsAutomationObject(strCLSID) Dim strSubKey IsAutomationObject = False strSubKey = "CLSID" & strCLSID & "Implemented Categories" If RegKeyExists(HKEY_CLASSES_ROOT, strSubKey) Then strSubKey = strSubKey & "{40FC6ED5-2438-11CF-A3DB-080036F12502}" If RegKeyExists(HKEY_CLASSES_ROOT, strSubKey) Then IsAutomationObject = True End If End If End Function Function IsProgrammable(strCLSID) IsProgrammable = RegKeyExists(HKEY_CLASSES_ROOT, _ "CLSID" & strCLSID & "Programmable") End Function Function GetCLSID(strProgID, strCLSID) Dim s GetCLSID = False If RegKeyExists(HKEY_CLASSES_ROOT, strProgID & "CLSID") Then objReg.GetStringValue HKEY_CLASSES_ROOT, strProgID & "CLSID", "", s If Not IsNull(s) Then strCLSID = s GetCLSID = True End If End If End Function |







