How can you check if an exe is already running?
Posted: Sun Sep 19, 2010 12:23 pm
I need to check if a particular exe is already running, because if it is not, I want to terminate the one trying to detect it?
Questions and answers about the LiveCode platform.
https://www.forums.livecode.com/
Code: Select all
function processExists pProcess
// Declare the variables.
local tTempValueStorage,tProcesses,tProcessResult
// Back up current settings. (So it doesn't interfere with your app if ever.)
put the hideConsoleWindows into tTempValueStorage
// Hide the console windows.
set the hideConsoleWindows to true
// Get the result from Windows' "tasklist" console.
put shell("tasklist /NH /FO CSV") into tProcesses
// Set default return value.
put false into tProcessResult
// Check the results.
set the itemDel to quote
repeat for each line tProcessLine in tProcesses
delete char 1 of tProcessLine
put item 1 of tProcessLine into tProcessLine
if tProcessLine is pProcess then
put true into tProcessResult
exit repeat
end if
end repeat
// Return the old value of the hideConsoleWindows property.
set the hideConsoleWindows to tTempValueStorage
// Output the result.
return tProcessResult
end processExists
Code: Select all
on mouseUp
answer processExists("notepad.exe")
end mouseUp
Thanks! If you still get problems with it, please don't hesitate toask.a-revuser wrote:Hi Shadowslash,
This is most helpful. I will be trying this out very soon. I expect many other users will be pleased with this code snippet as well.