Search code examples
batch-filewindows-10taskscheduler

How to debug task scheduler on win 10?


I'm trying to exectute the following bat every 15 minutes on my pc:

@ECHO OFF

SETLOCAL enabledelayedexpansion

SET host=http://dnsad.de/rest/
SET slideshowurl=http://dnsad.de/display/currentSlideshow/mac/
SET slideshowfolder=C:\Slideshow
SET ieprocess="iexplore.exe"
SET ignore_result=INFORMATION:

FOR /f "delims=" %%a IN ('getmac /v ^|find /i "Realtek"') DO (
    FOR %%b IN (%%a) DO (
        SET element=%%b
        IF "!element:~2,1!!element:~5,1!!element:~8,1!"=="---" set mac=%%b
    )
)

SET formattedmac=%mac:-=:%
SET macpath=%mac:-=_%

FOR /f "delims=" %%a IN ('curl -X GET %host%%formattedmac%') DO (
    FOR %%b IN (%%a) DO (
        SET update=%%b
    )
)

IF "%update%"=="[true]" (
    CD %ProgramFiles%\WinHTTrack\
    httrack %slideshowurl%%formattedmac% -q -O "C:\Slideshow" -s0 -B -a
    curl -X PUT %host%%formattedmac%

    START iexplore -k %slideshowfolder%\dnsad.de\display\currentSlideshow\mac\%macpath%.html
)

EXIT

The script works as it should when executed. Im getting the device's mac address, getting the expected server responses from curl, WinHTTrack is backing up the data correctly, curl updates the server fields and then the internet explorer gets opened with the updated,local html.

When scheduled as Task with win 7 it works as it should as well. When running the bat from Task Scheduler on Win 10 the last thing it does is the curl PUT, but the Internet Exploerer is never opened. The task is marked as succesful.

I am logged in as admin on Win 7 and Win 10. I tested pretty much every setting within the taskscheduler. Nothing seems to be working. Why doesnt the internet explorer start ?

[EDIT]

It seems that the option "Run whether user is logged on or not" causes the problem. But here is the catch: I'm displaying slideshows in Internet Explorer Kiosk Mode and need to get updated Data from my server to Display new Slideshows regularly. The mentioned option prevents the console from popping up when executing the bat file. If i "only execute if user is logged on" i do get the updated Data to display in Internet Explorer, but every 15 minutes a console window pops up for a second.

I tried exectuing with cmd /c "update" /min "PATH TO BAT" which dosesn't solve the problem.


Solution

  • As mentioned in my [Edit] the problem was the option "run whether user is logged on or not", which i used to prevent the command line window to pop up. When i use the option "only execute if user is logged on" i need to "wrap" the bat in a VBScript which doesnt open the cli. So by scheduling a vbs with the following lines:

    Set objShell = WScript.CreateObject("WScript.Shell")
    objShell.Run "cmd /c PATH\TO\BAT", 0, True
    

    i can execute the bat without a flashing cli.