• 设为首页
  • 收藏本站
  • 积分充值
  • VIP赞助
  • 手机版
  • 微博
  • 微信
    微信公众号 添加方式:
    1:搜索微信号(888888
    2:扫描左侧二维码
  • 快捷导航
    福建二哥 门户 查看主题

    vbs能调用的系统对象小结

    发布者: 姬7089 | 发布时间: 2025-8-14 00:53| 查看数: 40| 评论数: 0|帖子模式

    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对象大全”:
    1. Option Explicit

    2. Const HKEY_CLASSES_ROOT = &H80000000
    3. Dim arrProgID, strProgID, strCLSID
    4. Dim objReg, objFso, objFile, objShell

    5. Set objReg = GetObject("winmgmts:\\.\root\default:StdRegProv")
    6. Set objFso = CreateObject("Scripting.FileSystemObject")
    7. Set objShell = CreateObject("WScript.Shell")

    8. Set objFile = objFso.OpenTextFile("ProgID.txt", 2, True)

    9. 'By Demon
    10. 'http://demon.tw

    11. objReg.EnumKey HKEY_CLASSES_ROOT, "", arrProgID
    12. For Each strProgID In arrProgID
    13. If GetCLSID(strProgID, strCLSID) Then
    14.   If IsProgrammable(strCLSID) Or IsAutomationObject(strCLSID) Then
    15.    objFile.WriteLine strProgID
    16.   End If
    17. End If
    18. Next
    19. objShell.Run "ProgID.txt"

    20. Function RegKeyExists(hKey, strSubKey)
    21. Dim a, n
    22. n = objReg.EnumKey(hKey, strSubKey, a)
    23. If n = 0 Then
    24.   RegKeyExists = True
    25. Else
    26.   RegKeyExists = False
    27. End If
    28. End Function

    29. Function IsAutomationObject(strCLSID)
    30. Dim strSubKey
    31. IsAutomationObject = False
    32. strSubKey = "CLSID" & strCLSID & "\Implemented Categories"
    33. If RegKeyExists(HKEY_CLASSES_ROOT, strSubKey) Then
    34.   strSubKey = strSubKey & "{40FC6ED5-2438-11CF-A3DB-080036F12502}"
    35.   If RegKeyExists(HKEY_CLASSES_ROOT, strSubKey) Then
    36.    IsAutomationObject = True
    37.   End If
    38. End If
    39. End Function

    40. Function IsProgrammable(strCLSID)
    41. IsProgrammable = RegKeyExists(HKEY_CLASSES_ROOT, _
    42.   "CLSID" & strCLSID & "\Programmable")
    43. End Function

    44. Function GetCLSID(strProgID, strCLSID)
    45. Dim s
    46. GetCLSID = False
    47. If RegKeyExists(HKEY_CLASSES_ROOT, strProgID & "\CLSID") Then
    48.   objReg.GetStringValue HKEY_CLASSES_ROOT, strProgID & "\CLSID", "", s
    49.   If Not IsNull(s) Then
    50.    strCLSID = s
    51.    GetCLSID = True
    52.   End If
    53. End If
    54. 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函数自己来判断:
    1. Option Explicit

    2. Const HKEY_CLASSES_ROOT = &H80000000
    3. Dim arrProgID, strProgID, strCLSID
    4. Dim objReg, objFso, objFile, objShell, O

    5. Set objReg = GetObject("winmgmts:\\.\root\default:StdRegProv")
    6. Set objFso = CreateObject("Scripting.FileSystemObject")
    7. Set objShell = CreateObject("WScript.Shell")

    8. Set objFile = objFso.OpenTextFile("ProgID.txt", 2, True)

    9. 'By Demon
    10. 'http://demon.tw

    11. objReg.EnumKey HKEY_CLASSES_ROOT, "", arrProgID
    12. For Each strProgID In arrProgID
    13. If GetCLSID(strProgID, strCLSID) Then
    14.   If IsCreatable(strProgID) Then
    15.    objFile.WriteLine strProgID
    16.   End If
    17. End If
    18. Next
    19. objShell.Run "ProgID.txt"

    20. Function IsCreatable(strProgID)
    21. On Error Resume Next
    22. Dim O
    23. Set O = CreateObject(strProgID)
    24. If Err.Number = 0 Then
    25.   IsCreatable = True
    26. Else
    27.   IsCreatable = False
    28. End If
    29. Set O = Nothing
    30. Err.Clear
    31. End Function

    32. Function RegKeyExists(hKey, strSubKey)
    33. Dim a, n
    34. n = objReg.EnumKey(hKey, strSubKey, a)
    35. If n = 0 Then
    36.   RegKeyExists = True
    37. Else
    38.   RegKeyExists = False
    39. End If
    40. End Function

    41. Function GetCLSID(strProgID, strCLSID)
    42. Dim s
    43. GetCLSID = False
    44. If RegKeyExists(HKEY_CLASSES_ROOT, strProgID & "\CLSID") Then
    45.   objReg.GetStringValue HKEY_CLASSES_ROOT, strProgID & "\CLSID", "", s
    46.   If Not IsNull(s) Then
    47.    strCLSID = s
    48.    GetCLSID = True
    49.   End If
    50. End If
    51. End Function
    复制代码
    说了这么多,其实我真正想说的是,就算你用上面的脚本得到了“VBS对象大全”又有什么意义呢?我敢肯定的告诉你,这些对象里面有95%以上你从来都见过,也不知道它们是做什么的,更不用说去调用。
    我常用的VBS对象只有下面几个:
    1. ADODB.Stream
    2. InternetExplorer.Application
    3. Msxml2.XMLHTTP
    4. Scripting.Dictionary
    5. Scripting.FileSystemObject
    6. Shell.Application
    7. WScript.Shell
    复制代码
    把这些对象都弄懂了,VBS基本上就入门了。
    以上部分内容来自:http://demon.tw/programming/createobject-again.html

    来源:互联网
    免责声明:如果侵犯了您的权益,请联系站长(1277306191@qq.com),我们会及时删除侵权内容,谢谢合作!

    最新评论

    QQ Archiver 手机版 小黑屋 福建二哥 ( 闽ICP备2022004717号|闽公网安备35052402000345号 )

    Powered by Discuz! X3.5 © 2001-2023

    快速回复 返回顶部 返回列表