开发者

How to get the PID of IRunningTask (Task Scheduler 2.0 library)

开发者 https://www.devze.com 2023-01-31 21:54 出处:网络
I started a task using IRegisteredTask.Run() and got IRunningTask object. My Goal is to focus the main window of started task with SetForegrou开发者_运维问答ndWindow function.

I started a task using IRegisteredTask.Run() and got IRunningTask object.

My Goal is to focus the main window of started task with SetForegrou开发者_运维问答ndWindow function.

First i want to know the PID (Process ID) of the running task.

There is IRunningTask.EnginePID property, but it gives me the PID of some taskeng.exe process (Task Scheduler Engine), this is not my task...

How to get the PID of IRunningTask?


You are correct. The IRegisteredTask interface does not expose a PID property.

If you really need the PID, you might need to use the .Path and .Name properties of the IRegisteredTask and enumerate the currently running processes looking for a match. When you locate the currently running process that has the same path and name as your IRegisteredTask, you can then retrieve the PID. It's not pretty, but it should do the trick.


Can't you get it using IRunningTask.InstanceGuid (and then go through TaskScheduler.IRegisteredTaskCollection)?

--edited for completeness--

Since your final goal is to get the task itself, you can do that by using the unique GUID inside the engine's task collection.

0

精彩评论

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