找回密码
 加入
搜索
查看: 600|回复: 6

[网络通信] 【已解决】关于IF判断多个进程的问题

[复制链接]
发表于 2023-2-1 19:44:31 | 显示全部楼层 |阅读模式
本帖最后由 229989799 于 2023-2-1 21:18 编辑

各位新年好。大家好。
请问下,代码判断多个进程是否运行,在判断到第一个,它不存在就停止了,后面的进程不存在,它没判断出来,是不是写法有问题?


If ProcessExists("qq.exe") = 0 Then
        MsgBox(0,"","qq.exe未运行")
ElseIf ProcessExists("chrome.exe") = 0 Then
        MsgBox(0,"","chrome.exe未运行")
ElseIf ProcessExists("kugou.exe") = 0 Then
        MsgBox(0,"","kugou.exe未运行")
ElseIf ProcessExists("qqgame.exe") = 0 Then
        MsgBox(0,"","qqgame.exe未运行")
Else
        MsgBox(0,"","一切正常!")
EndIf



发表于 2023-2-1 20:03:08 | 显示全部楼层
Local $sInfo = ''
If Not ProcessExists('qq.exe') Then $sInfo &= 'qq.exe 未运行' & @LF
If Not ProcessExists('chrome.exe') Then $sInfo &= 'chrome.exe 未运行' & @LF
If Not ProcessExists('kugou.exe') Then $sInfo &= 'kugou.exe 未运行' & @LF
If Not ProcessExists('qqgame.exe') Then $sInfo &= 'qqgame.exe 未运行'
If $sInfo <> '' Then
        MsgBox(48, '', $sInfo)
Else
        MsgBox(0, '', '一切正常!')
EndIf

点评

请问斑竹,elseif是只能用一次吗?  发表于 2023-2-1 20:45
发表于 2023-2-1 20:06:44 | 显示全部楼层

牛A...


-=-=-=---==-==--==--==--==-
发表于 2023-2-1 20:07:46 | 显示全部楼层



_Chk_Process()

Func _Chk_Process()
        Local $sProcessStr = 'qq.exe|chrome.exe|kugou.exe|qqgame.exe'
        Local $aProcess = StringRegExp($sProcessStr, '[^\|]+', 3)
        If @error Then Return SetError(1, 0, '')
        Local $sUnRuningProcess = ''
        For $i = 0 To UBound($aProcess) - 1
                If Not ProcessExists($aProcess[$i]) Then
                        $sUnRuningProcess &= $aProcess[$i] & @CRLF
                EndIf
        Next
        If $sUnRuningProcess = ''  Then 
                Return MsgBox(512, '', "一切正常")
        Else
                Return MsgBox(16, '以下进程未运行',$sUnRuningProcess)
        EndIf        
EndFunc   ;==>_Chk_Process



点评

高级代码。酸Q大佬的帮忙  发表于 2023-2-1 20:50
发表于 2023-2-2 10:47:33 | 显示全部楼层
因为满足if或elseif条件后,后面的就不执行了,需要用if else嵌套实现。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-4-25 02:35 , Processed in 0.075469 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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