Is there a command to close a running program
Posted: 21 May 2011 07:28
I don't see such a command myself, so I wonder if it's possible to terminate a process on demand by scripting? Thanks!
Forum for XYplorer Users and Developers
https://www.xyplorer.com/xyfc/
Yes, via run or cmd.Huidong wrote:I don't see such a command myself, so I wonder if it's possible to terminate a process on demand by scripting? Thanks!
TSKILL is part of Windows 7. Alternatively, psexec as part of the Sysinternals Suite can be used.serendipity wrote:Yes, via run or cmd.Huidong wrote:I don't see such a command myself, so I wonder if it's possible to terminate a process on demand by scripting? Thanks!
Example:
Open notepad and run this:
::run "cmd /c TSKILL notepad";
notepad should close.
This is for XP though, not sure if this works on win7 or not.
You can omit .exe and use defraggler. You get the process names from task manager's process.Huidong wrote:It works for notepad on Win7, thanks! But I don't know how to do it in general. Say I want to close D:\Portable\Defraggler\Defraggler.exe, how to put quotes properly? I tried but none worked.
Sysinternals PSList can be used for this. It will return a errorlevel of 0 if the process is running and of 1 if it's not.Huidong wrote:Oh, one more question, how to use if...else... to close the program only if it's running? i.e. how to check if a program is running? Reason: I noticed that the command-line exe of defraggler (df.exe) does not work if the GUI exe is running, so after I wrote a command to defrag selected items, I'd like to add that check beforehand so that the GUI gets killed before attempting to run df.exe. Could you help?
Code: Select all
pslist defraggler.exe
if errorlevel 0 ( //Running.
tskill defraggler.exe
) else ( //Implies errorlevel 1 i.e. not running.
//Alternative operation.
) I tried the command above but defraggler is not killed! Why?serendipity wrote:You can omit .exe and use defraggler. You get the process names from task manager's process.Huidong wrote:It works for notepad on Win7, thanks! But I don't know how to do it in general. Say I want to close D:\Portable\Defraggler\Defraggler.exe, how to put quotes properly? I tried but none worked.
::run "cmd /c TSKILL defraggler";
I thought "Ho that's so cool!" killed defraggler before.Huidong wrote:I tried the command above but defraggler is not killed! Why?serendipity wrote:You can omit .exe and use defraggler. You get the process names from task manager's process.Huidong wrote:It works for notepad on Win7, thanks! But I don't know how to do it in general. Say I want to close D:\Portable\Defraggler\Defraggler.exe, how to put quotes properly? I tried but none worked.
::run "cmd /c TSKILL defraggler";
then ::run "cmd /c TSKILL defraggler"; should work.Huidong wrote:What's "image name"? The process name is just Defraggler.exe, is that what you're asking?
does not work!run "cmd /c TSKILL defraggler"