Board logo

标题: [技术讨论] vbs里使用.net对象 [打印本页]

作者: jyswjjgdwtdtj    时间: 2024-6-13 21:41     标题: 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()
复制代码





欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2