Detecting Process ID of the current cmd.exe

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
Squashman
Expert
Posts: 4114
Joined: 23 Dec 2011 13:59

Re: Detecting Process ID of the current cmd.exe

#46 Post by Squashman » 14 Oct 2017 15:53

So executing the batch file from a cmd prompt and from Windows Explorer says the parent process is Explorer.exe.
If I execute it from the cmd prompt like this.

Code: Select all

start process.bat

It comes back with cmd.exe

When run from Task Scheduler it says the parent process is svchost.exe.

aGerman
Expert
Posts: 3786
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Detecting Process ID of the current cmd.exe

#47 Post by aGerman » 14 Oct 2017 16:03

Squashman wrote:So executing the batch file from a cmd prompt and from Windows Explorer says the parent process is Explorer.exe.

Yes. If you used CALL in the cmd prompt no new process was created.

Squashman wrote:When run from Task Scheduler it says the parent process is svchost.exe.

One of the commenters at SO said the same. I didn't try to run it from a scheduled task. As I understood the comment it depends on the context the scheduled task was run. You could do some tests with the SYSTEM account or with your account but elevated.

Steffen

Post Reply