[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[技术讨论] vbs里使用.net对象

本帖最后由 jyswjjgdwtdtj 于 2024-6-13 21:44 编辑

出于或许是.net和vbs里对象规范不同 似乎很多对象都不能使用(瘫痪掉 失去属性和方法)
所以…没啥技术含量…图个乐子
  1. class dotnetobject
  2. public ps,ws,ie
  3. private sub class_initialize
  4. set ws=createobject("wscript.shell")
  5. set ps=ws.exec("powershell -windowstyle hidden")
  6. ps.stdin.writeline("[void][System.Reflection.Assembly]::LoadWithPartialName(""System.Windows.Forms"")")
  7. set ie=createobject("internetexplorer.application")
  8. ie.visible=false
  9. ps.stdin.writeline("[int]$iehwnd="&ie.hwnd)
  10. ps.stdin.writeline("$ie=0")
  11. ps.stdin.writeline("foreach($i in (new-object -comobject shell.application).windows()){if($i.hwnd -eq $iehwnd){$ie=$i}}")
  12. end sub
  13. public function getdotnetobject(objname)
  14. ps.stdin.writeline "$ie.putproperty(""psobject"",(new-object """&objname&"""))"
  15. do
  16. if isempty(ie.getproperty("psobject")) then
  17. wscript.sleep 20
  18. else
  19. exit do
  20. end if
  21. loop
  22. set getdotnetobject=ie.getproperty("psobject")
  23. end function
  24. private sub class_Terminate
  25. ie.quit()
  26. ps.stdin.writeline("exit")
  27. end sub
  28. end class
  29. set a=new dotnetobject
  30. set b=a.getdotnetobject("system.windows.forms.form")
  31. with b
  32. .Text = "Hello WinForm"  
  33. end with
  34. b.showdialog()
复制代码

返回列表