Hi, All,
What is the correct code to kill another Windows application with a LiveCode handler?
Should this work?
on MouseUp
kill process "anotherApp.exe"
end MouseUP
Thanks,
Kill Process in Windows OS
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Re: Kill Process in Windows OS
Hi Ken,
I am no expert, but "kill" is definitively no LiveCode reserved word, it sounds more like a "shell" syntax.
So this won't work, I'm afraid.
Best
Klaus
I am no expert, but "kill" is definitively no LiveCode reserved word, it sounds more like a "shell" syntax.
So this won't work, I'm afraid.
Best
Klaus
-
- VIP Livecode Opensource Backer
- Posts: 56
- Joined: Sat Apr 08, 2006 5:28 pm
- Location: Eau Claire, WI
- Contact:
Re: Kill Process in Windows OS
No, that won't work AFAIK because "kill" only works to kill processes that were launched with "open process" from inside LiveCode. I use a VBScript to do this, based on (usually) the process ID of the executable:
Where [[pProcName]] is replaced by the lowercase name of the executable you're trying to match ("calc.exe", "winword.exe", etc.). I store it in a stack custom property (like "uKillProcScript"), and then call it from LC like this:
Funky, but it works...
Code: Select all
Dim tResult
Set ProcessSet = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("select * from Win32_Process")
tResult = "Error: Process not found"
For each Process in ProcessSet
If Process.ExecutablePath <> "" Then
If LCase(Process.Caption)=[[pProcName]] Then
Process.Terminate (Process.ProcessID)
tResult = ""
Exit For
End If
End If
Next
result = tResult
Code: Select all
on KillProcess pProcName
put toLower(pProcName) into pProcName -- just in case
put the uKillProcScript of this stack into tScript
put merge(tScript) into tScript -- replaces the placeholder with the incoming param pProcName
do tScript as "VBScript"
if the result <> "" then
answer "You got an error: " && the result
end if
end KillProcess pProcName
Ken Ray
Sons of Thunder Software
Email: kray@sonsothunder.com
Web site: http://www.sonsothunder.com
Sons of Thunder Software
Email: kray@sonsothunder.com
Web site: http://www.sonsothunder.com
-
- Livecode Opensource Backer
- Posts: 66
- Joined: Sun Apr 15, 2007 2:54 pm
- Location: Albuquerque, NM USA
Re: Kill Process in Windows OS
Klaus & Ken
From a "mouseUP" handler, the following single line of code works in WIndows XP to "kill" another running application:
put shell("taskkill /im myApp.exe") into myresult
The shell command needed the " /im " switch to finally work correctly. The application name may include uppercase characters as long as the name is found among the process list of the task manager.
Thanks for your help.
From a "mouseUP" handler, the following single line of code works in WIndows XP to "kill" another running application:
put shell("taskkill /im myApp.exe") into myresult
The shell command needed the " /im " switch to finally work correctly. The application name may include uppercase characters as long as the name is found among the process list of the task manager.
Thanks for your help.
Ken