找回密码
 加入
搜索
查看: 4969|回复: 21

请高手帮我加一段代码,详情请进。

[复制链接]
发表于 2008-9-20 12:22:43 | 显示全部楼层 |阅读模式
下面代码请帮我添加一段每5分钟检查一次,先谢了。
$list = ProcessList()
for $i = 1 to $list[0][0]
  ;msgbox(0,"",$list[$i][0])
  Check_kill($list[$i][0])
next
Func Check_kill($task)
$file = FileOpen("test.txt", 0)
; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf
; Read in lines of text until the EOF is reached
While 1
    $line = FileReadLine($file)
    If $task = $line Then ExitLoop
    If @error = -1 Then      
        MsgBox(0, "提示","由于文件允许列表没有: " &$task &" 进程^_^!!!")
        ProcessClose($task)
        ExitLoop
    EndIf
    ;MsgBox(0, "Line read:", $line)
Wend
FileClose($file)
EndFunc

[ 本帖最后由 xg911335 于 2008-9-26 23:50 编辑 ]
发表于 2008-9-20 12:23:37 | 显示全部楼层
每5分钟循环一次?
发表于 2008-9-20 15:01:41 | 显示全部楼层
想要检查什么?看不明白

[ 本帖最后由 netegg 于 2008-9-20 15:05 编辑 ]
 楼主| 发表于 2008-9-20 17:47:44 | 显示全部楼层
我只是比喻了一个时间.代码有了我自己可以控制时间的长短啊.
 楼主| 发表于 2008-9-20 18:01:26 | 显示全部楼层
While 1
    check_task()
   sleep(300000)
WEnd
加上这一段能不能达到最好的效果?
发表于 2008-9-20 22:37:02 | 显示全部楼层
运行了一下,死机了....  -_-!!
发表于 2008-9-21 01:44:04 | 显示全部楼层
$begin = TimerInit()
$dif = 0
$i=0
While 1
do
    $dif = TimerDiff($begin)
Until $dif >= 300000
此处添加程序内容
        $begin = TimerInit()
        $dif = 0
WEnd


能不用的情况下,千万不要用sleep...俺以前做bat脚本深受其害...
发表于 2008-9-21 10:15:33 | 显示全部楼层
$begin = TimerInit()
While TimerDiff($begin)< 3000000
MsgBox("","",  TimerDiff($begin))
WEnd
这样的?
发表于 2008-9-21 11:25:17 | 显示全部楼层
原帖由 netegg 于 2008-9-21 10:15 发表
$begin = TimerInit()
While TimerDiff($begin)< 3000000
MsgBox("","",  TimerDiff($begin))
WEnd
这样的?


这个条件就不对了...LZ要求的是每5分钟,TimerDiff($begin)< 3000000是计时间隔小于5分钟,意思完全相反...
俺上面的代码应该是对的嘞...
每5分钟跳出do...until...循环,运行一遍程序体,然后重置TimerInit()和TimerDiff($begin),进入下一轮do...until...循环...

[ 本帖最后由 palkiller 于 2008-9-21 11:26 编辑 ]
发表于 2008-9-21 11:45:47 | 显示全部楼层
原帖由 palkiller 于 2008-9-21 11:25 发表


这个条件就不对了...LZ要求的是每5分钟,TimerDiff($begin)< 3000000是计时间隔小于5分钟,意思完全相反...
俺上面的代码应该是对的嘞...
每5分钟跳出do...until...循环,运行一遍程序体,然后重置TimerInit() ...


对,忘了是每五分钟了,汗

[ 本帖最后由 netegg 于 2008-9-21 11:57 编辑 ]
 楼主| 发表于 2008-9-22 16:53:37 | 显示全部楼层
$begin = TimerInit()
$dif = 0
$i=0
While 1
do
    $dif = TimerDiff($begin)
Until $dif >= 300000
;----------------------------------------------------------------------------------
; 列出所有进程
$list = ProcessList()
for $i = 1 to $list[0][0]
  ;msgbox(0,"",$list[$i][0])
  Check_kill($list[$i][0])
next

Func Check_kill($task)
        $file = FileOpen("test.txt", 0)

; Check if file opened for reading OK
        If $file = -1 Then
                MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

; Read in lines of text until the EOF is reached
While 1
    $line = FileReadLine($file)
    If $task = $line Then ExitLoop
    If @error = -1 Then      
        MsgBox(0, "提示","由于文件允许列表没有: " &$task &" 程序将结束该进程^_^!!!")
        ProcessClose($task)
        ExitLoop
    EndIf
    ;MsgBox(0, "Line read:", $line)
Wend
FileClose($file)
EndFunc
;------------------------------------------------------------------------------------
        $begin = TimerInit()
        $dif = 0
WEnd

(16,1) : ERROR: missing Wend.
Func
(4,1) : REF: missing Wend.
While
(41,1) : ERROR: syntax error
WEnd
2 error(s), 0 warning(s)怎么解决啊?
发表于 2008-9-22 17:02:59 | 显示全部楼层
Until $dif >= 300000这行下面的wend呢
 楼主| 发表于 2008-9-22 17:06:09 | 显示全部楼层
在最后面的啊
        $begin = TimerInit()
        $dif = 0
WEnd
发表于 2008-9-22 17:31:55 | 显示全部楼层
while里面套while?能这么用吗?没想过
还有,如果是最后的那个wend,中间怎么套出func了

[ 本帖最后由 netegg 于 2008-9-22 17:39 编辑 ]
 楼主| 发表于 2008-9-22 17:42:26 | 显示全部楼层
$list = ProcessList()
for $a = 1 to $list[0][0]
  ;msgbox(0,"",$list[$i][0])
  Check_kill($list[$a][0])
next
Func Check_kill($task)
$file = FileOpen("test.txt", 0)
; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf
; Read in lines of text until the EOF is reached
$begin = TimerInit()
$dif = 0
$i=0
While 1
Do
        $dif = TimerDiff($begin)
        Until $dif >= 1000
;time
                $line = FileReadLine($file)
                If $task = $line Then ExitLoop
                If @error = -1 Then      
                        MsgBox(0, "提示","由于文件允许列表没有: " &$task &" 进程^_^!!!")
                        ProcessClose($task)
                        ExitLoop
                EndIf
    ;MsgBox(0, "Line read:", $line)
        $begin = TimerInit()
        $dif = 0
Wend
FileClose($file)
EndFunc
对不起,我是才学这个东东。很多东西都不了解。为什么运行了要等很久才有反应,我设置的时间才1000毫秒啊,还有好象每1000毫秒对比列表里的一行,怎么不是对列表所有行对比一次.代码是不是有什么问题啊?帮我在看看.先谢了.

[ 本帖最后由 xg911335 于 2008-9-22 17:58 编辑 ]
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-12 14:56 , Processed in 0.078892 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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