How to use wmic job get/list in CMD to get process name and location?

45,053

Solution 1

The following will work, though you only need "CommandLine" or "ExecutablePath" - not both:

wmic process where "ProcessID=1111" get CommandLine, ExecutablePath

It will return something like the following, showing where the program for PID 1111 is running:

"C:\Program Files (x86)\Common Files\MyProgram\Agent\agent.exe"

Solution 2

Here is something to begin.

Get the process identifier of the service Schedule

wmic service where name='schedule' get ProcessId
ProcessId
288

Get the process which parent process identifier is the Schedule service

wmic process where ParentProcessId=288

Edited

I don't think that in Microsoft system jobs are what you are looking for :

A job object allows groups of processes to be managed as a unit. Job objects are namable, securable, shareable objects that control attributes of the processes associated with them. Operations performed on a job object affect all processes associated with the job object. Examples include enforcing limits such as working set size and process priority or terminating all processes associated with a job.

I think you are looking for process.

To answer your question I look for the processes started by the schedule service. If you want the exact location, it's given by the property ExecutablePath.

wmic process where ParentProcessId=288 get ExecutablePath
ExecutablePath
C:\Windows\system32\wuauclt.exe
Share:
45,053
Admin
Author by

Admin

Updated on May 29, 2020

Comments

  • Admin
    Admin almost 4 years

    I need to get the exact location of a process name that a scheduled job is executing. I want to use WMIC JOB (if you have any other suggestions.. let me know) to get that, but I don't know HOW exactly. I've tried several variations but no luck so far.

    How should I?

  • Admin
    Admin over 12 years
    The unnecessary comments were removed. Those commands are related to how to get to Schedule service, not to the location of a process name (+process name). Am I missing somethig? Why did you use WMIC SERVICE / PROCESS and not JOB? Is that part of all of this? Thanks.
  • Admin
    Admin over 12 years
    I see. But my point is not necessary to look for processes started by the schedule service. For example, if the schedule service is disabled, the code won't find all what I need.
  • Admin
    Admin over 12 years
    I've got some code to do what I need, but it's not short as WMIC (JOB or whatever) can be, and that's why I search for alternative(s).
  • Admin
    Admin over 12 years
    I thought about something in this direction- WMIC job "TaskName" get command. Something like that. Thanks again.
  • JPBlanc
    JPBlanc over 12 years
    I modify my answer about Job.
  • Admin
    Admin over 12 years
    What does it mean in the buttom line?
  • Admin
    Admin over 12 years
    Agreed. But I tried >< long time ago, but I tried alot of variations. I'll try again soon. In the meantime, if you have some ideas- let me know them.
  • Admin
    Admin about 12 years
    OK. Problem is not solved, and it can't be unfortunately. You can lock this thread. Thanks for everyone :)