Batch Script to Launch Kodi Fails When Run By Task Scheduler
#1
I'm trying to run a simple batch script to launch Kodi after my machine wakes from sleep using Task Scheduler.

@echo off
timeout 15
start C:\"Program Files (x86)"\Kodi\Kodi.exe
Exit

The purpose is to launch Kodi so that my backup add-on can run and create a backup. I want to run this at 5 am so I'm using Task Scheduler to wake my machine and launch Kodi.

The script works without any issues if I manually run it. However, if I set Task Scheduler to run it at a specified time it fails and breaks Kodi. By break I mean, if I try to launch Kodi manually after Task Scheduler has attempt to launch it using this script, I receive the following error:

Unable to create application. Exiting

This error will continue until I restart the machine. Any ideas?
Reply
#2
Not 100% sure on this but I think the schedule service by default has GUI that is in the background that you can not see. You can set it to launch as the interactive user. You can do that in the task scheduler settings for the item you created. It is probably also running as a different user by default. Probably Administrator or System instead of your normal user. You will want to set that too. As all the data is under each user and not global.

Also unless you have Kodi set to turn itself off your script will basically spin up an instance of kodi then exit the batch script. The kodi.exe you started with the 'start' command will continue along on merry way and the main batch file will exit. So you may be trying to start up two instances? You should see the other instance sitting in the background running in task manager.

Here is a similar thread to what you probably want to do http://forum.kodi.tv/showthread.php?tid=176036 You probably will want a timeout of say 5 mins then kill the kodi task?

probably something like

@echo off
timeout /T 15
start "C:\Program Files (x86)\Kodi\Kodi.exe"
timeout /T 300
taskkill /IM kodi.exe
Exit

Others here may have a better way. You may want to ask under the particular plugin thread you are using in the plugin forum here. They may have run into something similar.
Reply
#3
(2016-12-06, 10:05)lharms Wrote: Not 100% sure on this but I think the schedule service by default has GUI that is in the background that you can not see. You can set it to launch as the interactive user. You can do that in the task scheduler settings for the item you created. It is probably also running as a different user by default. Probably Administrator or System instead of your normal user. You will want to set that too. As all the data is under each user and not global.

Also unless you have Kodi set to turn itself off your script will basically spin up an instance of kodi then exit the batch script. The kodi.exe you started with the 'start' command will continue along on merry way and the main batch file will exit. So you may be trying to start up two instances? You should see the other instance sitting in the background running in task manager.

Here is a similar thread to what you probably want to do http://forum.kodi.tv/showthread.php?tid=176036 You probably will want a timeout of say 5 mins then kill the kodi task?

probably something like

@echo off
timeout /T 15
start "C:\Program Files (x86)\Kodi\Kodi.exe"
timeout /T 300
taskkill /IM kodi.exe
Exit

Others here may have a better way. You may want to ask under the particular plugin thread you are using in the plugin forum here. They may have run into something similar.

I'll give this a try and let you know. I was thinking the task was running in the background as another user as well. The timeout is a good idea as well. I wasn't too worried about Kodi continuing to run as I had a task scheduled to put the machine to sleep, but killing the task is not a bad idea.

Thanks for the suggestions.
Reply
#4
I have not had a chance to try this yet, but I think this may be the issue:

http://superuser.com/questions/656964/wh...-all-users

Since my script was intended to wake the system, I enabled "Run whether user is logged on or not" option. This however, does run the application using the active user account. So the operation is hidden and likely causing an issue. The suggestion is to change the user that runs the task, to a group. In this case, the Users group. I will try this later tonight and report back.
Reply
#5
So in the end the issue was the user running the task. I mistakenly assumed that because my machine was going to be in Sleep/Standby when the task was due to run, that I needed to enable the option to run the task even if the user was not logged in. In actuality, the task event itself triggers the machine to wake, then the task runs. So I did not need to enable this option. So I can leave the option for the task to run when the selected user, in this case the user account that I normally run Kodi under is logged in. Because by the time the task runs, the machine wakes and the account is logged in.

Not sure how many others have/will run into this issue, but I hope this info helps.
Reply

Logout Mark Read Team Forum Stats Members Help
Batch Script to Launch Kodi Fails When Run By Task Scheduler0