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.
精彩评论