Search code examples
scheduled-tasksraspberry-pi3windows-10-iot-corewindowsiotwindows-iot-core-10

Windows IOT task not run on startup (but it runs on manual command)


I created a .bat file which execute .ps1 file. Then I added scheduled tasks:

schtasks /Create /SC ONSTART /TN MyApp /TR "c:\Projects\MyApp\Startup.bat" /RU SYSTEM

and power down Raspberry Pi 3B+. When I supply power again, my ASP.NET Core 3.0 app is not running. If I connect to Raspberry Pi power shell and run

schtasks /Run /TN MyApp

application runs (web page is displayed).

Is there any logs, where I could found what went wrong?
Has anybody have any idea, why task is not ran on application start up?

Every post I found mention that task also doesn't run/execute if tried manually. But this is not my case.


Solution

  • You can use ETW on Windows IoT Core to trace the event log for schedule tasks. The Microsoft-Windows-TaskScheduler provider can be used to track the detail info when a scheduled task run or stop.

    enter image description here

    BTW, I'm not sure what's the content in your Startup.bat and *.ps1 file. I created the files with following content, it works for me.

    Startup.bat

    @echo off
    powershell -executionpolicy bypass -File "C:\Projects\MyApp\start.ps1"
    

    start.ps1

    Start-Process -NoNewWindow -FilePath "C:\Projects\MyApp\NetCoreWebApp.exe"
    

    Before you created the scheduled task, you can test the scripts step by step to ensure the script works fine.