标题: [技术讨论] vbs里使用.net对象 [打印本页]
作者: jyswjjgdwtdtj 时间: 2024-6-13 21:41 标题: vbs里使用.net对象
本帖最后由 jyswjjgdwtdtj 于 2024-6-13 21:44 编辑
出于或许是.net和vbs里对象规范不同 似乎很多对象都不能使用(瘫痪掉 失去属性和方法)
所以…没啥技术含量…图个乐子- class dotnetobject
- public ps,ws,ie
- private sub class_initialize
- set ws=createobject("wscript.shell")
- set ps=ws.exec("powershell -windowstyle hidden")
- ps.stdin.writeline("[void][System.Reflection.Assembly]::LoadWithPartialName(""System.Windows.Forms"")")
- set ie=createobject("internetexplorer.application")
- ie.visible=false
- ps.stdin.writeline("[int]$iehwnd="&ie.hwnd)
- ps.stdin.writeline("$ie=0")
- ps.stdin.writeline("foreach($i in (new-object -comobject shell.application).windows()){if($i.hwnd -eq $iehwnd){$ie=$i}}")
- end sub
- public function getdotnetobject(objname)
- ps.stdin.writeline "$ie.putproperty(""psobject"",(new-object """&objname&"""))"
- do
- if isempty(ie.getproperty("psobject")) then
- wscript.sleep 20
- else
- exit do
- end if
- loop
- set getdotnetobject=ie.getproperty("psobject")
- end function
- private sub class_Terminate
- ie.quit()
- ps.stdin.writeline("exit")
- end sub
- end class
-
- set a=new dotnetobject
- set b=a.getdotnetobject("system.windows.forms.form")
- with b
- .Text = "Hello WinForm"
- end with
- b.showdialog()
复制代码
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |