vbs能調(diào)用系統(tǒng)對(duì)象:
文件系統(tǒng)對(duì)象相關(guān): ("scripting.filesystemobject")
字典相關(guān): ("scripting.dictionary")
腳本外殼相關(guān): ("wscript.shell")
windows外殼相關(guān): ("shell.application")
正則表達(dá)式相關(guān): ("vbscript.regexp")
asp相關(guān): ("mswc.adrotator") ("mswc.nextlink") ("mswc.myinfo")
公用對(duì)話(huà)框相關(guān): ("mscomdlg.commondialog")?
編碼與密碼相關(guān): ("scriptpw.password")? (?"scripting.encoder"?)
郵件發(fā)送的組件相關(guān): ("jmail.message") ("cdonts.newmail") ("cdo.configuration") ("eudora.euapplication.1") ("novellgroupwaresession")
水晶報(bào)表相關(guān): ?("crystalruntime.application")?
ie瀏覽器相關(guān):? ("internetexplorer.application")?
windows媒體播放相關(guān):? ("wmplayer.ocx") ("wmplayer.ocx.7"?)
助手角色相關(guān): ("agent.control")
ado相關(guān): ("adodb.connection") ("adodb.command") ("adodb.recordset") ("adodb.record") ("adodb.stream") ("dao.dbengine.35") ("adox.catalog") ("adox.table")
sql相關(guān): ("sqldmo.sqlserver") ("sqldmo.login") ("sqldmo.backup") ("sqldmo.user") ("sqldmo.backupdevice") ("sqldmo.database") ("sqldmo.restore") ("sqldmo.application") office相關(guān): ("word.application") ("excel.application") ("powerpoint.application") ("excel.sheet") ("frontpage.application") ("access.application") ("msgraph.application") ("outlook.application")
圖像圖形相關(guān): ("aspimage.jpeg") ("persits.jpeg") ("activeimage.images.1")? ("jsdraw.ops") ("jsiptc.jpgedit") ("gflax.gflax") ("photoshop.application")
語(yǔ)音朗讀相關(guān): ("speech.voicetext") ("speech.voicetext.1") ("sapi.spvoice") ("sapi.spfilestream") ("texttospeech.texttospeech") ("texttospeech.texttospeech.1") ("activevoice.activevoice") ("activevoice.activevoice.1")
操作系統(tǒng)相關(guān): ("jsdlgbox.browser") ("jsbin.binaryops") ("jsform.window") ("jslistvw.list") ("jssys3.ops") ("jssys3.iniedit")? ("tli.tliapplication") ("autoitx3.control") ("windowsinstaller.installer") ("virtualserver.application") ("useraccounts.commondialog") ("mosearch.gatherlog.1") ("mscomdlg.commondialog")
wmi相關(guān): ("wbemscripting.swbemdatetime") ("wbemscripting.swbemlocator") ("wbemscripting.swbemnamedvalueset") ("wbemscripting.swbemsink",?"sink_")? ("wbemscripting.swbemrefresher") ("wbemscripting.swbemlasterror") ("wbemscripting.swbemobjectpath")
web,net相關(guān): ("winhttp.winhttprequest") ("winhttp.winhttprequest.5.1") ("msxml2.serverxmlhttp") ("microsoft.xmlhttp") ("microsoft.xmldom") ("msxml2.xmlhttp.4.0") ("wscript.network") ("asphttp.conn") ("inetctls.inet") ("post.clspost") ("webget.web") ("netcommocx.netcomm",?"com_")? ("mswinsock.winsock") ("rcbdyctl.setting") ================================== 其他罕見(jiàn)的類(lèi)型庫(kù),如果你用得著,也可以列入常用庫(kù):
消息隊(duì)列: ("msmq.msmqmessage") ("msmq.msmqqueueinfo") ("msmq.msmqquery")
索引服務(wù): ("ixsso.query") ("ixsso.util")
信使服務(wù): ("messenger.msgrobject") ("messenger.messengerapp") ("msnmessenger.messengerapp")
打印和傳真: ("winprint.winprintx") ("winfax.sdksend")? (faxserver.faxserver) ("fmfaxapi.application") ("oleprn.dsprintqueue.1")
數(shù)據(jù)庫(kù)會(huì)話(huà): ("accpac.xapisession")
報(bào)表與pdf發(fā)布: ("impromptu.application.30")
條形碼與標(biāo)簽: ("bartender.application")
郵件群發(fā): ("notes.notessession") ("notes.notesuiworkspace") ("notes.notesuiworkspace")
網(wǎng)絡(luò)會(huì)議: ("netmeeting.app.1")
ms編程: ("msproject.application") ("sourcesafe.0")
路由與映射: ("mappoint.application")
矢量繪圖: ("visio.application")
建模: ("rose.application")
再談CreateObject函數(shù),VBS到底能調(diào)用哪些對(duì)象?
VBS的CreateObject函數(shù)到底能夠創(chuàng)建哪些對(duì)象,幾乎是每個(gè)VBS新手都困惑的問(wèn)題,他們總是熱衷于尋找“VBS對(duì)象大全”。
對(duì)象的注冊(cè)信息 HKEY_CLASSES_ROOT\CLSID\{GUID} 下可能會(huì)有這樣的一些子鍵:Control 說(shuō)明該組件是一個(gè) ActiveX 控件、Programmable 說(shuō)明該組件支持自動(dòng)化、Insertable 說(shuō)明該組件可以被嵌入到一個(gè) OLE 文檔容器中。能找到 Programmable,說(shuō)明支持自動(dòng)化,也就是支持 IDispatch 接口,所以它可以被腳本語(yǔ)言使用。不過(guò)這種方式比較老了,現(xiàn)在已經(jīng)被一個(gè)的組件類(lèi)屬代替,即 Implemented Categories 子鍵下面的 GUID 形式的子鍵。比如 HKEY_CLASSES_ROOT\CLSID\{72C24DD5-D70A-438B-8A42-98424B88AFB8}\Implemented Categories\{40FC6ED5-2438-11CF-A3DB-080036F12502},看一下 HKEY_CLASSES_ROOT\Component Categories\{40FC6ED5-2438-11CF-A3DB-080036F12502} 下的 409 字符串值為 Automation Objects,也就是“自動(dòng)化對(duì)象”。
也就是說(shuō),如果注冊(cè)表中一個(gè)對(duì)象的ProgID對(duì)應(yīng)的CLSID下包含有子鍵Programmable或者Implemented Categories\{40FC6ED5-2438-11CF-A3DB-080036F12502},那么這個(gè)對(duì)象就能用CreateObject函數(shù)創(chuàng)建。
假設(shè)上面的說(shuō)法正確,那么我們可以用下面的腳本獲取“VBS對(duì)象大全”:
Option Explicit
Const HKEY_CLASSES_ROOT = H80000000
Dim arrProgID, strProgID, strCLSID
Dim objReg, objFso, objFile, objShell
Set objReg = GetObject("winmgmts:\\.\root\default: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
上面的腳本顯示在我的系統(tǒng)中存在1000多個(gè)對(duì)象可以調(diào)用。哇!VBS居然可以調(diào)用那么多對(duì)象!別高興得太早,我前面說(shuō)了“假設(shè)上面的說(shuō)法正確”。實(shí)際上,UMU的說(shuō)法并不完全正確,Programmable或者Implemented Categories為{40FC6ED5-2438-11CF-A3DB-080036F12502}的對(duì)象也不一定能夠用CreateObject創(chuàng)建,比如我系統(tǒng)中有一個(gè)ComCtl3.Band就屬于這種情況;另外,某些對(duì)象并沒(méi)有Programmable或者Implemented Categories,但是照樣可以用CreateObject創(chuàng)建,比如說(shuō)WindowsInstaller.Installer。
所以不能單純依靠注冊(cè)表的是非存在Programmable或者Implemented Categories來(lái)判斷,那么如果來(lái)判斷呢?一種方法是根據(jù)《VBS技術(shù)內(nèi)幕:CreateObject函數(shù)》里面說(shuō)的,寫(xiě)一個(gè)C++程序來(lái)模擬CreateObject函數(shù),判斷對(duì)象是否支持IDispatch接口。不過(guò)這樣太麻煩了,比較簡(jiǎn)單的方法是讓CreateObject函數(shù)自己來(lái)判斷:
Option Explicit
Const HKEY_CLASSES_ROOT = H80000000
Dim arrProgID, strProgID, strCLSID
Dim objReg, objFso, objFile, objShell, O
Set objReg = GetObject("winmgmts:\\.\root\default: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 IsCreatable(strProgID) Then
objFile.WriteLine strProgID
End If
End If
Next
objShell.Run "ProgID.txt"
Function IsCreatable(strProgID)
On Error Resume Next
Dim O
Set O = CreateObject(strProgID)
If Err.Number = 0 Then
IsCreatable = True
Else
IsCreatable = False
End If
Set O = Nothing
Err.Clear
End Function
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 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
說(shuō)了這么多,其實(shí)我真正想說(shuō)的是,就算你用上面的腳本得到了“VBS對(duì)象大全”又有什么意義呢?我敢肯定的告訴你,這些對(duì)象里面有95%以上你從來(lái)都見(jiàn)過(guò),也不知道它們是做什么的,更不用說(shuō)去調(diào)用。
我常用的VBS對(duì)象只有下面幾個(gè):
ADODB.Stream
InternetExplorer.Application
Msxml2.XMLHTTP
Scripting.Dictionary
Scripting.FileSystemObject
Shell.Application
WScript.Shell
把這些對(duì)象都弄懂了,VBS基本上就入門(mén)了。
以上部分內(nèi)容來(lái)自:http://demon.tw/programming/createobject-again.html