找回密码
 加入
搜索
查看: 5999|回复: 16

[AU3基础] _iecreate创建得到的项目$oie如何取得其对应的进程id? [已解决]

  [复制链接]
发表于 2011-12-17 19:45:18 | 显示全部楼层 |阅读模式
本帖最后由 kevinch 于 2011-12-20 19:01 编辑

如我用ie.au3函数_iecreate创建浏览页面
#include <ie.au3>
$oie=_IECreate("http://www.autoitx.com/forum-4-1.html",1,1,1,0)
MsgBox(0,"",IsHWnd($oie)&@tab&ObjName($oie))
所得到的$oie项目,如何才能取得其对应的进程ID呢?或者是其父进程的ID?望高手指教。
发表于 2011-12-17 21:30:26 | 显示全部楼层
$oie只是一个文档对象,进程还是ie进程
 楼主| 发表于 2011-12-17 22:11:34 | 显示全部楼层
我想获取pid,比如我不是用ie打开的,而是第三方浏览器,如何取得这个浏览器程序的pid呢?
 楼主| 发表于 2011-12-18 18:06:43 | 显示全部楼层
继续寻找解决办法
发表于 2011-12-18 18:26:25 | 显示全部楼层

#include <ie.au3>
#include <winapi.au3>
$oie=_IECreate("http://www.autoitx.com/forum-4-1.html");,1,1,1,0)
Local $iProcessId,$iThreadid
$iThreadid = _WinAPI_GetWindowThreadProcessId($oie.hwnd,$iProcessId)
MsgBox(0,0,$iProcessId)

评分

参与人数 1金钱 +40 收起 理由
kevinch + 40 感谢出手相助

查看全部评分

 楼主| 发表于 2011-12-18 18:52:27 | 显示全部楼层
ceoguang 发表于 2011-12-18 18:26

感谢出手相助!
在引用$oie.hwnd时出错,不知是否版本不同的原因,我现在用的是3.3.6.1
发表于 2011-12-18 18:57:26 | 显示全部楼层
应该与版本无关
因为对象成员是存在的
如果出错,请调用 objevent 来获取得错误信息
 楼主| 发表于 2011-12-18 19:22:01 | 显示全部楼层
err.description is:        
err.windescription:        未指定的错误
err.number is:         80020009
err.lastdllerror is:         0
err.scriptline is:         7
err.source is:        
err.helpfile is:        
err.helpcontext is:         0
有用的信息似乎不多
发表于 2011-12-18 20:49:06 | 显示全部楼层
#include <ie.au3>
#include <winapi.au3>
$oie=_IECreate("http://www.autoitx.com/forum-4-1.html");,1,1,1,0)
Local $iProcessId,$iThreadid
$iThreadid = _WinAPI_GetWindowThreadProcessId($oie.hwnd(),$iProcessId)
MsgBox(0,0,$iProcessId)
http://msdn.microsoft.com/en-us/library/aa752126(v=VS.85).aspx

评分

参与人数 1金钱 +40 收起 理由
kevinch + 40 再次感谢

查看全部评分

 楼主| 发表于 2011-12-18 21:01:25 | 显示全部楼层
http://msdn.microsoft.com/en-us/library/aa752126(v=VS.85).aspx
ceoguang 发表于 2011-12-18 20:49
#include <ie.au3>
#include <winapi.au3>

Global $oMyError,$g_eventerror = 0

$oie=_IECreate("http://www.autoitx.com/forum-4-1.html",1,1,1,0)
$oMyError=ObjEvent("AutoIt.Error","MyErrFunc")
MsgBox(0,"",$oie.document.body.innertext)
Local $iProcessId,$iThreadid
$iThreadid = _WinAPI_GetWindowThreadProcessId($oie.hwnd,$iProcessId)
MsgBox(0,0,$iProcessId)

Func MyErrFunc()

  ConsoleWrite("We intercepted a COM Error !"      & @CRLF  & @CRLF & _
             "err.description is: "    & @TAB & $oMyError.description    & @CRLF & _
             "err.windescription:"     & @TAB & $oMyError.windescription & @CRLF & _
             "err.number is: "         & @TAB & hex($oMyError.number,8)  & @CRLF & _
             "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
             "err.scriptline is: "     & @TAB & $oMyError.scriptline     & @CRLF & _
             "err.source is: "         & @TAB & $oMyError.source         & @CRLF & _
             "err.helpfile is: "       & @TAB & $oMyError.helpfile       & @CRLF & _
             "err.helpcontext is: "    & @TAB & $oMyError.helpcontext          & @CRLF _
            )
            
    Local $err = $oMyError.number
    If $err = 0 Then $err = -1
    
    $g_eventerror = $err  ; to check for after this function returns
Endfunc
我试了其他属性可以,这个hwnd一直不行,好奇怪
 楼主| 发表于 2011-12-18 22:02:42 | 显示全部楼层
#include <ie.au3>

Global $oMyError,$g_eventerror = 0

$oie=_IECreate("http://www.autoitx.com/forum-4-1.html",1,1,1,0)
$oMyError=ObjEvent("AutoIt.Error","MyErrFunc")

$arr=stringsplit($oie.fullname,"")
MsgBox(0,0,ProcessExists($arr[UBound($arr)-1]))

Func MyErrFunc()
  ConsoleWrite("We intercepted a COM Error !"      & @CRLF  & @CRLF & _
             "err.description is: "    & @TAB & $oMyError.description    & @CRLF & _
             "err.windescription:"     & @TAB & $oMyError.windescription & @CRLF & _
             "err.number is: "         & @TAB & hex($oMyError.number,8)  & @CRLF & _
             "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
             "err.scriptline is: "     & @TAB & $oMyError.scriptline     & @CRLF & _
             "err.source is: "         & @TAB & $oMyError.source         & @CRLF & _
             "err.helpfile is: "       & @TAB & $oMyError.helpfile       & @CRLF & _
             "err.helpcontext is: "    & @TAB & $oMyError.helpcontext          & @CRLF _
            )
            
    Local $err = $oMyError.number
    If $err = 0 Then $err = -1
    $g_eventerror = $err  ; to check for after this function returns
Endfunc
暂时这样解决了,不过如果存在多个相同进程的话,不知道要如何解决啦
发表于 2011-12-19 00:18:49 | 显示全部楼层
都是高手,观看给位表演!
发表于 2011-12-19 01:12:37 | 显示全部楼层
$oie=_IECreate("http://www.autoitx.com/forum-4-1.html")
等待IE加载完成即可
注意_IECreate的参数
5#及9#的代码都是没有问题的
 楼主| 发表于 2011-12-19 18:52:59 | 显示全部楼层
我用的是世界之窗浏览器,不知是否这个的原因,hwnd始终报错
发表于 2011-12-19 19:10:55 | 显示全部楼层
#include <IE.au3>
$oIE = _IECreate('www.baidu.com')
$Hwnd = _IEPropertyGet($oIE, 'hwnd')
MsgBox(0,'进程PID',WinGetProcess($Hwnd))

评分

参与人数 1金钱 +40 收起 理由
kevinch + 40 感谢出手相助

查看全部评分

您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-6-16 11:15 , Processed in 0.084692 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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