Check for running exe program
Re: Check for running exe program
Thanks highend, but I don't need a change. I have no problem specifying the whole exe filename including extension especially knowing that's how the file is displayed in Task Manager. I was only testing to see if it needed the extension and what the results would be. Thanks.
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440
Re: Check for running exe program
I modified it a bit more...
It supports the "?=any single character" & "*=zero or more characters" wildcard chars now.
You can now either use the process name with / without the trailing .exe and any combination of the wildcard chars.
This saves you from using a foreach loop if you want to test for running processes that share a common pattern.
E.g.
Will return true if any of the following processes are running:
Evernote [Portable].exe
Evernote.exe
EvernoteClipper.exe
EvernoteTray.exe
It supports the "?=any single character" & "*=zero or more characters" wildcard chars now.
You can now either use the process name with / without the trailing .exe and any combination of the wildcard chars.
This saves you from using a foreach loop if you want to test for running processes that share a common pattern.
E.g.
Code: Select all
if (isProcessRunning("evernote*")) { echo "is running..."; }
Evernote [Portable].exe
Evernote.exe
EvernoteClipper.exe
EvernoteTray.exe
Code: Select all
function isProcessRunning($process) {
$process = regexreplace($process, "([\[\]^$.+(){}])", "\$1");
$process = """" . replace(replace($process, "?", ".{1}"), "*", ".*?") . "(\.exe|"")";
if (regexmatches(runret("cmd /c @TASKLIST /NH /FO CSV"), $process)) { return 1; }
return;
}
// Example of wildcard use. Will find "FlashPlayerPlugin_17_0_0_134.exe
if (isProcessRunning("?lash*134")) { echo "is running..."; }
One of my scripts helped you out? Please donate via Paypal or paypal_donate (at) stdmail (dot) de
Re: Check for running exe program
Cool highend. I tried quite a few different combinations like '?gent and stepping through it I saw 'agent'. I tried *agent and saw 'PDagent' as well as 'agent'. I closed 'agent.exe' and then saw only 'PDagent'. Very nice!
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440
Re: Check for running exe program
highend, any reason to not do an exact match? [ed. regarding a deprecated version.]
And also what's the @ doing there?
btw, here's my "fork":
And also what's the @ doing there?
btw, here's my "fork":
Code: Select all
function isProcessRunning($process) {
//if (regexmatches(runret("cmd /c @TASKLIST /NH"), "^" . regexreplace($process, "([\[\]^$.+(){}])", "\$1"))) { return 1; }
$cmdExe = (%osbitness% == 64) ? "%windir%\sysWOW64\cmd.exe" : "%windir%\system32\cmd.exe" ;
$report = runret(quote($cmdExe) . '/C TASKLIST /NH /FO CSV /FI "IMAGENAME eq '. replace($process, "'", "\'") .'"');
$result = trim(gettoken($report, 1, '","'),'"');
if (recase($result) == recase($process)) { return 1; } else { return 'NOT FOUND'; }
}
text isprocessrunning("xyplorer.exe");
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]
[ this user is asleep ]
Re: Check for running exe program
Hey Sammay, your version seems to work fine for exact file names, but it may be a bit too exact in that it appears to be case sensitive. XYplorer works; whereas xyplorer.exe does not.
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440
Re: Check for running exe program
fixed, thanks.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]
[ this user is asleep ]
Re: Check for running exe program
Couldn't resist trying it out, too. Works nice as well. What's the difference to highend's version? I noticed some OS bitness business in there?
Re: Check for running exe program
I heartily recommend highend's latest version ( ^up there^ ).
Mine:
1) always does exact matches
2) and most of the detection is done by system, whereas highend uses some high-end regexp (and I understand he *really* likes regexps... )
Mine:
1) always does exact matches
2) and most of the detection is done by system, whereas highend uses some high-end regexp (and I understand he *really* likes regexps... )
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]
[ this user is asleep ]
Re: Check for running exe program
Ooops - how could I miss that update. Thanks for the up-pointer.SammaySarkar wrote:highend's latest version ( ^up there^ ).
Re: Check for running exe program
Thanks Sammay, that did the trick. I suppose you could have used "LikeI" instead of "==" and recasing. It works as well.
Code: Select all
if ($result LikeI $process) { return Found; } else { return 'NOT FOUND'; }
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440
Re: Check for running exe program
I decided against it, what if the process name had [] etc and they got evaluated? no need to take a risk.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]
[ this user is asleep ]
Re: Check for running exe program
another version of my fork:[edited]
Code: Select all
FUNCTION isprocessrunning($process, $data = 'count') {
/*
Checks if a process is running. Checks by process name only, no path.
$process the process to check for. Only filename without path has to be used.
$data what data to return. One of the following
count number of matching processes (default)
pid PIDs of matching processes comma-separated
anything else returns raw results when any process matches
*/
$return = '';
$cmdExe = (%osbitness% == 64) ? "%windir%\sysWOW64\cmd.exe" : "%windir%\system32\cmd.exe" ;
$report = trim(runret(quote($cmdExe) . '/C TASKLIST /FO CSV /FI "IMAGENAME eq '. replace($process, "'", "\'") .'"'), <crlf>);
$result = trim(gettoken(gettoken($report,2,<crlf>), 1, '","'), '"', 'L');
if (recase($result) == recase($process)) {
if ($data == 'pid') {
foreach($line, $report, <crlf>){
$pid = trim(gettoken($line, 2, '","', '"'));
if ($pid != '') && (regexreplace($pid,'^\d*') != '') { continue; } //to skip beginning "pid" field name
$pids = (isset($pids) ? $pids : '') . ',' . $pid;
}
$return = replace($pids, ',', '',,, 1);
}
elseif ($data == 'count') {
//tasklist lists processes one each line
$return = (gettoken($report, 'count', <crlf>) - 1); //discount fieldnames line
}
else { $return = $report; }
}
elseif ($data == 'count') { $return = 0; }
return $return;
}
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]
[ this user is asleep ]