[URGENT] Batch file end a task like task manager does.

March 6, 2012 at 12:44:30
Specs: Windows 7, 4gb
I need a batch file to end a process like the task manager does, not killing it or force closing it. How does the task manager do it, and is it even possible with a batch file? PS please also read my other question named 'A bat file to locate the newest log file & get a text string' Thanks!


ALSO how do you do a comment in a batch file? Like using '//' in java, so that it only shows up in the file.


See More: [URGENT] Batch file end a task like task manager does.

Report •


#1
March 6, 2012 at 15:23:49
the only way a batch file can kill a task to my knowledge is the taskkill command

to comment in a batch file, either use the command "rem" or make the comment a tag

ex.
rem this is a comment the file will not process it
:this makes a "goto" tag but it will not affect the way the program runs

if you're wondering there is not a way to comment on the same line that code is on


Report •

#2
March 6, 2012 at 15:51:51
Ok thanks for the comment solve. I knew about taskkill but is there a specific way to run it that will simulate the task manager ending a process?

Report •

#3
March 6, 2012 at 16:09:19
as far as I know, taskkill is how the task manager does it

Report •

Related Solutions

#4
March 6, 2012 at 16:12:29
But how does it do it? (/t /f etc) What combination of those

Report •

#5
March 6, 2012 at 16:41:20
The exact method that Task Manager uses is undocumented. It does not use the taskkill command line tool but ultimately uses the same method.

Note that all such methods are inherently unsafe. The only safe method of terminating a process is to ask it to end itself by closing it's window. If the process does not have a window this method is not possible. Aside from that there is no truly safe way to terminate a process.


Report •

#6
March 6, 2012 at 16:43:17
Hmm... thanks for the info I guess, anyone else have any suggestions?

Report •

#7
March 6, 2012 at 16:45:54
Urgent? To who? Not me. In fact, it's so not urgent to me, I'd rather discuss who would consider it urgent, and how that would affect me. I guess it makes me not want to answer the question, and that is an effect on me. So it does affect me. Huh. Oh well, back to video games.

"End Process" calls TerminateProcess(). This could be considered "killing it," and I think taskkill does something similar.
"End Task" uses SendMessageTimeout() to send a WM_CLOSE to the application in question. This gives the process a chance to close itself.


How To Ask Questions The Smart Way


Report •

#8
March 6, 2012 at 16:49:42
probably /f - why does it matter??

Report •

#9
March 7, 2012 at 06:01:12
Ok thanks Razor2.3 but how would I do that in a batch file? Could I see an example to end process.exe?

Report •

#10
March 7, 2012 at 06:44:29
I had nothing better to do this morning, so I connected the debugger to taskkill.exe.

Taskkill calls PostMessage() to send a WM_CLOSE. Taskkill /F calls TerminateProcess().

So just run taskkill without the /F switch.

How To Ask Questions The Smart Way


Report •

#11
March 7, 2012 at 07:20:44
So just taskkill process.exe??

Report •

#12
March 7, 2012 at 07:52:01
C:\>taskkill notepad.exe
ERROR: Invalid argument/option - 'notepad.exe'.
Type "TASKKILL /?" for usage.
Apparently not.

C:\>taskkill /im notepad.exe
SUCCESS: Sent termination signal to the process "notepad.exe" with PID 5928.

How To Ask Questions The Smart Way


Report •

#13
March 7, 2012 at 07:56:07
Yes but when I do that it kills the window. What I'm trying to accomplish is a batch file that safely ends my game window when I'm about to die. There is a program(exe) that someone made that ends the game without me dying, but whenever I've used taskkill at all(ive tried /im /f /t and combinations) I die. The exe I can use is not a batch so its loads a bit slow and plus I'd like to have my own. Is something like this not possible in batch?

Report •

#14
March 7, 2012 at 08:08:45
If the game is designed to kill you when you close the game, then that's how the game is designed.

The "program that someone made" probably patches the executable in memory, much like any other trainer. If this is an online game, then you have effectively broken our rules, and that makes me sad.

How To Ask Questions The Smart Way


Report •

#15
March 7, 2012 at 09:17:12
If I end the game's process with the task manager I dont die though.... same with the program, which made me think there's a way with some coding language to simulate the task manager ending a process...

Report •


Ask Question