【已解决】关于IF判断多个进程的问题
本帖最后由 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
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 afan 发表于 2023-2-1 20:03
牛A...
-=-=-=---==-==--==--==--==-
_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
因为满足if或elseif条件后,后面的就不执行了,需要用if else嵌套实现。
页:
[1]