找回密码
 加入
搜索
查看: 1480|回复: 7

如何将进程检测与托盘图表结合

[复制链接]
发表于 2009-7-27 15:27:18 | 显示全部楼层 |阅读模式
本帖最后由 cjmbbbbb 于 2009-7-27 16:03 编辑

我检测迅雷进程是否存在:
While 1
        If ProcessExists("Thunder5.exe") Then
                Sleep(600000)
        Else
                Run("Thunder.exe")
        EndIf
WEnd
想与托盘图标相结合:
#NoTrayIcon
#Include <Constants.au3>

Opt("TrayMenuMode", 1)

$aboutitem = TrayCreateItem("关于")
TrayCreateItem("")
$exititem = TrayCreateItem("退出")

TraySetState()

While 1
        $msg = TrayGetMsg()
        Select
                Case $msg = $aboutitem
                        MsgBox(64, "关于:", "进程检测")
                Case $msg = $exititem
                        ExitLoop
        EndSelect
WEnd
Exit
发表于 2009-7-27 15:49:37 | 显示全部楼层
可以把实现程序写成一个FUNC函数,然后调用就可以了,实现代码如下,因为采用循环加一形式,可能等待时间不一定很准,等待时间不要写成SLEEP(600000),会引起托盘菜单无响应。。。
#NoTrayIcon
#include <Constants.au3>
Global $time
Opt("TrayMenuMode", 1)

$aboutitem = TrayCreateItem("关于")
TrayCreateItem("")
$exititem = TrayCreateItem("退出")

TraySetState()

While 1
        $msg = TrayGetMsg()
        Select
                Case $msg = $aboutitem
                        MsgBox(64, "关于:", "进程检测")
                Case $msg = $exititem
                        ProcessClose("one.exe")
                        ExitLoop
        EndSelect
        Sleep(100)
        $time = $time + 1
        If $time = 6000 Then
                RunThunder()
                $time = 0
        EndIf
WEnd

Func RunThunder()
        If ProcessExists("Thunder5.exe") = 0 Then
                Run("Thunder.exe")
        EndIf
EndFunc   ;==>RunThunder
 楼主| 发表于 2009-7-27 15:55:04 | 显示全部楼层
本帖最后由 cjmbbbbb 于 2009-7-27 15:56 编辑

谢谢!我测试一下!!
sleep写长了是怕太耗内存
发表于 2009-7-27 16:26:49 | 显示全部楼层
这个最好用 AdlibEnable() 函数,不然点击托盘菜单会有设定的延时
 楼主| 发表于 2009-7-27 18:56:21 | 显示全部楼层
多谢楼上的!
 楼主| 发表于 2009-7-28 03:54:46 | 显示全部楼层
本帖最后由 cjmbbbbb 于 2009-7-28 03:56 编辑

测试后,两位的都不好.....
AdlibEnable() 不知为何循环不了
llssky2003 大侠的延时让整个托盘都慢半拍了..........
最后我逆向思维...........
#NoTrayIcon
#include <Constants.au3>

Opt("TrayMenuMode", 1)
Opt("trayOnEventMode", 1)

$aboutitem = TrayCreateItem("关于")
TrayItemSetOnEvent($aboutitem, "TrayMsg")
TrayCreateItem("")
$exititem = TrayCreateItem("退出")
TrayItemSetOnEvent($exititem, "TrayMsg")

TraySetState()

While 1
        Sleep(6000)
        If ProcessExists("Thunder5.exe") = 0 Then
                Run("Thunder.exe")
        EndIf
WEnd

Func TrayMsg()
        Switch @TRAY_ID
                Case $aboutitem
                        MsgBox(64, "关于本小软", "迅雷进程检测!")
                Case $exititem
                        Exit
        EndSwitch
EndFunc
还是要感谢你们
发表于 2009-7-28 11:36:29 | 显示全部楼层
呵呵,AdlibEnable() 可以循环啊~ 就2#改一下:
#NoTrayIcon
Opt("TrayMenuMode", 1)

$aboutitem = TrayCreateItem("关于")
TrayCreateItem("")
$exititem = TrayCreateItem("退出")
TraySetState()

AdlibEnable('RunThunder', 6000)

While 1
        $msg = TrayGetMsg()
        Select
                Case $msg = $aboutitem
                        MsgBox(64, "关于:", "进程检测")
                Case $msg = $exititem
                        exit
        EndSelect
WEnd

Func RunThunder()
        If ProcessExists("Thunder5.exe") = 0 Then
                Run("Thunder.exe")
        endif
EndFunc   ;==>RunThunder
 楼主| 发表于 2009-7-28 17:11:10 | 显示全部楼层
哎呀,原来我把AdlibEnable('RunThunder', 6000)放while里了.............
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-2 08:49 , Processed in 0.076090 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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