mtvtop 发表于 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,但有时会报错,停止运行,请问代码哪有问题?

mtvtop 发表于 2011-11-30 09:31:37

求高手解决

mtvtop 发表于 2011-11-30 10:14:27

报错图片已经上传

ceoguang 发表于 2011-11-30 10:30:24

这是COM的调用失败导致的。
看帮助

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

mtvtop 发表于 2011-11-30 10:52:18

回复 4# ceoguang

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

这个函数没有用过!看了很多帮助都没有理解,能不能给个完整代码?谢谢

dnbj2010 发表于 2011-11-30 11:09:08

楼主,你这个代码只能限制IE的,如果用别的浏览器,就无效了。

mtvtop 发表于 2011-11-30 13:53:41

回复 6# dnbj2010

是呀,你有什么好的方法没有?

mtvtop 发表于 2011-11-30 22:41:18

求高手帮忙解决

mtvtop 发表于 2011-12-1 18:38:04

回复 4# ceoguang


    能不能继续帮助一下,方分感激

502762378 发表于 2011-12-1 18:49:15

ie设置内容审查程序,可以注册表操作批量后台搞。

ceoguang 发表于 2011-12-1 19:42:40

回复ceoguang


    能不能继续帮助一下,方分感激
mtvtop 发表于 2011-12-1 18:38 http://www.autoitx.com/images/common/back.gif
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

mtvtop 发表于 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

kn007 发表于 2011-12-2 01:32:33

回复 12# mtvtop


    在 循环中
while里面
加入
sleep(1)
可解决,你没让程序休息,肯定cpu消耗大

mtvtop 发表于 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

mtvtop 发表于 2011-12-2 21:31:08

回复 13# kn007

大神问题已经解决,但又有个新问题,能不能继续解决一下,谢谢!
页: [1] 2
查看完整版本: 限定只能访问指定网址程序出错!隐藏进程的问题