开发者

How to terminate a process and its parent from command prompt

开发者 https://www.devze.com 2023-03-07 19:59 出处:网络
I have a process that is launched from command prompt - file.bat, although its parent cmd.exe needs to be terminated as well. The only problem is there are other instances of cmd.exe is there any way

I have a process that is launched from command prompt - file.bat, although its parent cmd.exe needs to be terminated as well. The only problem is there are other instances of cmd.exe is there any way of terminating the process file.bat - without deleting o开发者_StackOverflowther instances of cmd.exe

(I can't simply terminate the cmd.exe process, as I dont know the PID in this case)


You could try parsing the output of the PsList utility from Sysinternals.

You can get it from: http://technet.microsoft.com -> search for "sysinternals"

When you run "PsList -t" you'll see a list of processes, with children indented from the left margin. Here's a snippet:

How to terminate a process and its parent from command prompt

The first numeric column is the PID. You didn't mention what kind of language you're writing your script in, but it shouldn't be too hard to iterate over the lines, and use a stack-like structure to store the current descent-path. When you reach the PID of the desired process, you'll be able to examine the stack to get the parent info.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号