当前位置: 移动技术网 > IT编程>脚本编程>VBScript > vbs能调用的系统对象小结

vbs能调用的系统对象小结

2018年05月11日  | 移动技术网IT编程  | 我要评论

vbs能调用系统对象:

文件系统对象相关: ("scripting.filesystemobject")
字典相关: ("scripting.dictionary")
脚本外壳相关: ("wscript.shell")
windows外壳相关: ("shell.application")
正则表达式相关: ("vbscript.regexp")
asp相关: ("mswc.adrotator") ("mswc.nextlink") ("mswc.myinfo")
公用对话框相关: ("mscomdlg.commondialog")?
编码与密码相关: ("scriptpw.password")? (?"scripting.encoder"?)
邮件发送的组件相关: ("jmail.message") ("cdonts.newmail") ("cdo.configuration") ("eudora.euapplication.1") ("novellgroupwaresession")
水晶报表相关: ?("crystalruntime.application")?
ie浏览器相关:? ("internetexplorer.application")?
windows媒体播放相关:? ("wmplayer.ocx") ("wmplayer.ocx.7"?)
助手角色相关: ("agent.control")
ado相关: ("adodb.connection") ("adodb.command") ("adodb.recordset") ("adodb.record") ("adodb.stream") ("dao.dbengine.35") ("adox.catalog") ("adox.table")
sql相关: ("sqldmo.sqlserver") ("sqldmo.login") ("sqldmo.backup") ("sqldmo.user") ("sqldmo.backupdevice") ("sqldmo.database") ("sqldmo.restore") ("sqldmo.application") office相关: ("word.application") ("excel.application") ("powerpoint.application") ("excel.sheet") ("frontpage.application") ("access.application") ("msgraph.application") ("outlook.application")
图像图形相关: ("aspimage.jpeg") ("persits.jpeg") ("activeimage.images.1")? ("jsdraw.ops") ("jsiptc.jpgedit") ("gflax.gflax") ("photoshop.application")
语音朗读相关: ("speech.voicetext") ("speech.voicetext.1") ("sapi.spvoice") ("sapi.spfilestream") ("texttospeech.texttospeech") ("texttospeech.texttospeech.1") ("activevoice.activevoice") ("activevoice.activevoice.1")
操作系统相关: ("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相关: ("wbemscripting.swbemdatetime") ("wbemscripting.swbemlocator") ("wbemscripting.swbemnamedvalueset") ("wbemscripting.swbemsink",?"sink_")? ("wbemscripting.swbemrefresher") ("wbemscripting.swbemlasterror") ("wbemscripting.swbemobjectpath")
web,net相关: ("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") ================================== 其他罕见的类型库,如果你用得着,也可以列入常用库:
消息队列: ("msmq.msmqmessage") ("msmq.msmqqueueinfo") ("msmq.msmqquery")
索引服务: ("ixsso.query") ("ixsso.util")
信使服务: ("messenger.msgrobject") ("messenger.messengerapp") ("msnmessenger.messengerapp")
打印和传真: ("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_root\clsid\{guid} 下可能会有这样的一些子键:control 说明该组件是一个 activex 控件、programmable 说明该组件支持自动化、insertable 说明该组件可以被嵌入到一个 ole 文档容器中。能找到 programmable,说明支持自动化,也就是支持 idispatch 接口,所以它可以被脚本语言使用。不过这种方式比较老了,现在已经被一个的组件类属代替,即 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,也就是“自动化对象”。

也就是说,如果注册表中一个对象的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:\\.\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

上面的脚本显示在我的系统中存在1000多个对象可以调用。哇!vbs居然可以调用那么多对象!别高兴得太早,我前面说了“假设上面的说法正确”。实际上,umu的说法并不完全正确,programmable或者implemented categories为{40fc6ed5-2438-11cf-a3db-080036f12502}的对象也不一定能够用createobject创建,比如我系统中有一个comctl3.band就属于这种情况;另外,某些对象并没有programmable或者implemented categories,但是照样可以用createobject创建,比如说windowsinstaller.installer。

所以不能单纯依靠注册表的是非存在programmable或者implemented categories来判断,那么如果来判断呢?一种方法是根据《vbs技术内幕:createobject函数》里面说的,写一个c++程序来模拟createobject函数,判断对象是否支持idispatch接口。不过这样太麻烦了,比较简单的方法是让createobject函数自己来判断:

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

说了这么多,其实我真正想说的是,就算你用上面的脚本得到了“vbs对象大全”又有什么意义呢?我敢肯定的告诉你,这些对象里面有95%以上你从来都见过,也不知道它们是做什么的,更不用说去调用。

我常用的vbs对象只有下面几个:

adodb.stream
internetexplorer.application
msxml2.xmlhttp
scripting.dictionary
scripting.filesystemobject
shell.application
wscript.shell

把这些对象都弄懂了,vbs基本上就入门了。

以上部分内容来自:

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网