Windowsのタスクスケジューラで設定されたタスクの親プロセスのメモ。
タスクスケジューラのプロセスの親子関係についてはこちらの記事に良くまとめられている。
以下は参照先の記事からの抜粋。
- Windows 10よりも前のWindowsシステムではスケジュールされたタスクは
taskeng.exeによって実行される。 - Windows 10以降のWindowsシステムではスケジュールされたタスクは
Task Schedulerサービスをホストしているsvchost.exe(C:\WINDOWS\system32\svchost.exe -k netsvcs -p -s Schedule) によって実行される。
記事を読んでいて、schtasksコマンドのrunオプションでタスクが実行された場合、親プロセスはどうなるか気になったので調べてみた。(schtasks.exeが親プロセスになるのか?)
以下のコマンドを Window 7とWindow 10でそれぞれ実行してProcess Monitorでプロセスの親子関係を確認してみた。
schtasks /create /sc ONLOGON /tn test_task /tr "C:\Windows\notepad.exe"
上記のコマンドはtest_taskという名前のタスクを作成する。このタスクはユーザーのログオン時にメモ帳を起動する。
schtasks /run /tn test_task
上記のコマンドはtest_taskタスクを即座に実行する。
Windows 7での検証結果
コマンドプロンプトを管理者権限で立ち上げ、schtasksコマンドのcreateオプションでtest_taskタスクを作成し、runオプションで即座に実行した。
C:\Windows\system32>schtasks /create /sc ONLOGON /tn test_task /tr "C:\Windows\n
otepad.exe"
SUCCESS: The scheduled task "test_task" has successfully been created.
C:\Windows\system32>schtasks /run /tn test_task
SUCCESS: Attempted to run the scheduled task "test_task".
C:\Windows\system32>
Process Monitorで確認したところ、notepad.exe (メモ帳)の直接の親プロセスはtaskeng.exeになっていた。


Windows 10での検証結果
Windows 7と同様のschtasksコマンドでtest_taskタスクを作成して実行し、Process Monitorで確認したところ、notepad.exeの直接の親プロセスはsvchost.exeとなっていた。


検証のまとめ
schtasksコマンドのrunオプションでタスクを実行した場合、
- Windows 7ではタスクの親プロセスは
taskeng.exeになる。 - Windows 10ではタスクの親プロセスは
svchost.exe(C:\WINDOWS\system32\svchost.exe -k netsvcs -p -s Schedule) になる。