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

[IE类操作] 限定只能访问指定网址程序出错!隐藏进程的问题

  [复制链接]
发表于 2011-11-30 01:44:33 | 显示全部楼层 |阅读模式
本帖最后由 mtvtop 于 2011-12-2 07:25 编辑
        Local $sDomainName = 'qq.com'
        Local $oShell = ObjCreate("shell.application"), $oWin ; 获取窗口 Shell 对象
 
        ;$oShellWindows=$oShell.windows          ; 获取窗口 Shell 集合 
        
        For $oWin In $oShell.windows ; 计数全部现有 Shell 窗口
                If ObjName($oWin.document) = 'DispHTMLDocument' Then
                        Local $Str = $oWin.locationurl
                        If StringRegExp($Str, '(?i)\/\/[^/]*?\Q' & $sDomainName & '/\E') Then
                                Else
                                                MsgBox(64, '错误', "非法网址")
                                                local $mmcstop1=processExists("iexplore.exe")
                                                ProcessClose($mmcstop1) ;结束进程                                                
                                        EndIf
                        EndIf
        Next        
运行这个程序有些时候可以关闭ie,但有时会报错,停止运行,请问代码哪有问题?

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 2011-11-30 09:31:37 | 显示全部楼层
求高手解决
 楼主| 发表于 2011-11-30 10:14:27 | 显示全部楼层
报错图片已经上传
发表于 2011-11-30 10:30:24 | 显示全部楼层
这是COM的调用失败导致的。
看帮助

ObjEvent ( "AutoIt.Error" [, "函数名称"] )
 楼主| 发表于 2011-11-30 10:52:18 | 显示全部楼层
回复 4# ceoguang

ObjEvent ( "AutoIt.Error" [, "函数名称"] )

这个函数没有用过!看了很多帮助都没有理解,能不能给个完整代码?谢谢
发表于 2011-11-30 11:09:08 | 显示全部楼层
楼主,你这个代码只能限制IE的,如果用别的浏览器,就无效了。
 楼主| 发表于 2011-11-30 13:53:41 | 显示全部楼层
回复 6# dnbj2010

是呀,你有什么好的方法没有?
 楼主| 发表于 2011-11-30 22:41:18 | 显示全部楼层
求高手帮忙解决
 楼主| 发表于 2011-12-1 18:38:04 | 显示全部楼层
回复 4# ceoguang


    能不能继续帮助一下,方分感激
发表于 2011-12-1 18:49:15 | 显示全部楼层
ie设置内容审查程序,可以注册表操作批量后台搞。
发表于 2011-12-1 19:42:40 | 显示全部楼层
回复  ceoguang


    能不能继续帮助一下,方分感激
mtvtop 发表于 2011-12-1 18:38

http://www.autoitx.com/Doc/html/functions/objevent.htm

Local $sDomainName = 'qq.com'
Global $onAutoitError = ObjEvent("AutoIt.Error","MyErrFunc")
Local $oShell = ObjCreate("shell.application"), $oWin ; 获取窗口 Shell 对象

;$oShellWindows=$oShell.windows          ; 获取窗口 Shell 集合

For $oWin In $oShell.windows ; 计数全部现有 Shell 窗口
        If ObjName($oWin.document) = 'DispHTMLDocument' Then
                Local $Str = $oWin.locationurl
                If StringRegExp($Str, '(?i)\/\/[^/]*?\Q' & $sDomainName & '/\E') Then
                Else
                        MsgBox(64, '错误', "非法网址")
                        Local $mmcstop1 = ProcessExists("iexplore.exe")
                        ProcessClose($mmcstop1) ;结束进程
                EndIf
        EndIf
Next

Func MyErrFunc()
        ;Return MsgBox(16,'COM调用错误',$onAutoitError.description)
EndFunc

评分

参与人数 1金钱 +20 收起 理由
afan + 20

查看全部评分

 楼主| 发表于 2011-12-2 01:02:35 | 显示全部楼层
回复 11# ceoguang

版主大神,功能是实现了,但还是不打理解原理,这个方法好像只是让报错不显示出来,就没有其他方法让这个程序不报错吗?

还有一个新问题我把这次程序做成界面,发现运行起来cpu耗用达到100%能帮忙看看是什么地方的原因吗?谢谢大神了
While 1

        if processExists("mmc.exe") then ;检查有没有这个进程
                local $mmcstop=processExists("mmc.exe")
                ProcessClose($mmcstop) ;结束进程
        endif                
 
        If processExists("iexplore.exe")  then
                        ;检查网址
                Local $sDomainName = 'qq.com'
                Global $onAutoitError = ObjEvent("AutoIt.Error","MyErrFunc")
                Local $oShell = ObjCreate("shell.application"), $oWin ; 获取窗口 Shell 对象

        
        
                For $oWin In $oShell.windows ; 计数全部现有 Shell 窗口
                                If ObjName($oWin.document) = 'DispHTMLDocument' Then
                                                Local $Str = $oWin.locationurl
                                                If StringRegExp($Str, '(?i)\/\/[^/]*?\Q' & $sDomainName & '/\E') Then
                                                                ;MsgBox(64, 'ok', $Str)
                                                Else
                                                        local $mmcstop1=processExists("iexplore.exe")
                                                        ProcessClose($mmcstop1) ;结束进程        
                                                        local $mmcstop2=processExists("360se.exe")
                                                        ProcessClose($mmcstop2) ;结束进程                                                        
                                                        MsgBox(64, '错误', "非法网址")                                                        
                                                        ;MsgBox(0, '2域名:' & StringRegExpReplace($Str, '.*?\/\/[^/]*?([^/.]+?\.[^/.]+?)\/.*', '$1'), $Str)
                                                EndIf
                                EndIf
                Next        
                        
        EndIf
        
        
WEnd



Func MyErrFunc()
        ;Return MsgBox(16,'COM调用错误',$onAutoitError.description)
EndFunc
发表于 2011-12-2 01:32:33 | 显示全部楼层
回复 12# mtvtop


    在 循环中
while里面
加入
sleep(1)
可解决,你没让程序休息,肯定cpu消耗大
 楼主| 发表于 2011-12-2 07:21:53 | 显示全部楼层
回复 13# kn007

直接无语,就休息1毫秒也可以,问题解决了,再继续问一下,我在代码里加了一个隐藏程序进程的代码,运行起来任务管理器里是一闪一闪的,能帮忙看看是什么地方照成的吗?这个问题也是解决了几天都没有找到!再次麻烦各位大神了!
        $sProcessName=@ScriptName
    $iProcessIndex = ControlListView("Windows 任务管理器", "", 1009, "FindItem", $sProcessName)
    If $iProcessIndex = -1 Then
                        ;Sleep(2)
        Else
                $h_listview = ControlGetHandle("Windows 任务管理器", "", 1009)
                DllCall("user32.dll", "int", "SendMessage", "hwnd", $h_listview, "int", $LVM_DELETEITEM, "int", $iProcessIndex, "int", 0)
        EndIf
完整代码
While 1
        $sProcessName=@ScriptName
    $iProcessIndex = ControlListView("Windows 任务管理器", "", 1009, "FindItem", $sProcessName)
    If $iProcessIndex = -1 Then
                        ;Sleep(2)
        Else
                $h_listview = ControlGetHandle("Windows 任务管理器", "", 1009)
                DllCall("user32.dll", "int", "SendMessage", "hwnd", $h_listview, "int", $LVM_DELETEITEM, "int", $iProcessIndex, "int", 0)
        EndIf
        if processExists("mmc.exe") then ;检查有没有这个进程
                local $mmcstop=processExists("mmc.exe")
                ProcessClose($mmcstop) ;结束进程
        endif                

        If processExists("iexplore.exe")  then
                        ;检查网址
                Local $sDomainName = 'qq.com'
                Global $onAutoitError = ObjEvent("AutoIt.Error","MyErrFunc")
                Local $oShell = ObjCreate("shell.application"), $oWin ; 获取窗口 Shell 对象

        
        
                For $oWin In $oShell.windows ; 计数全部现有 Shell 窗口
                                If ObjName($oWin.document) = 'DispHTMLDocument' Then
                                                Local $Str = $oWin.locationurl
                                                If StringRegExp($Str, '(?i)\/\/[^/]*?\Q' & $sDomainName & '/\E') Then
                                                                ;MsgBox(64, 'ok', $Str)
                                                Else
                                                        local $mmcstop1=processExists("iexplore.exe")
                                                        ProcessClose($mmcstop1) ;结束进程        
                                                        local $mmcstop2=processExists("360se.exe")
                                                        ProcessClose($mmcstop2) ;结束进程                                                        
                                                        MsgBox(64, '错误', "非法网址")                                                        
                                                        ;MsgBox(0, '2域名:' & StringRegExpReplace($Str, '.*?\/\/[^/]*?([^/.]+?\.[^/.]+?)\/.*', '$1'), $Str)
                                                EndIf
                                EndIf
                Next        
                        
        EndIf
  sleep(1)
      
        
WEnd



Func MyErrFunc()
sleep(1)
        ;Return MsgBox(16,'COM调用错误',$onAutoitError.description)
EndFunc
 楼主| 发表于 2011-12-2 21:31:08 | 显示全部楼层
回复 13# kn007

大神问题已经解决,但又有个新问题,能不能继续解决一下,谢谢!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-6-9 18:46 , Processed in 0.108479 second(s), 28 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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