Kodi Community Forum

Full Version: When Kodi Starts, Also Start Another .exe
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I want C:\Users\DAN\Documents\Fan\HTFanControl.exe to start when I start Kodi.

I don't know if this is the correct approach or if there is an easier or better way?

I've created service.autoexec folder in the C:\Users\DAN\AppData\Roaming\Kodi\addons folder.

In it I've created addon.xml containing

 
Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="service.autoexec" name="Autoexec Service" version="1.0.0" provider-name="DAN">
<requires>
<import addon="xbmc.python" version="3.0.0"/>
</requires>
<extension point="xbmc.service" library="autoexec.py">
</extension>
<extension point="xbmc.addon.metadata">
<summary lang="en_GB">Automatically run python code when Kodi starts.</summary>
<description lang="en_GB">The Autoexec Service will automatically be run on Kodi startup.</description>
<platform>all</platform>
<license>GNU GENERAL PUBLIC LICENSE Version 2</license>
</extension>
</addon>

I've created another file autoexec.py that is empty. What code would go in here?

Any help or advice appreciated.
python:
import subprocess
subprocess.Popen('C:\\Users\\DAN\\Documents\\Fan\\HTFanControl.exe')

https://docs.python.org/3/library/subprocess.html
Excellent.  Thank you.
my pleasure
(2023-03-07, 04:10)jepsizofye Wrote: [ -> ]
python:
import subprocess
subprocess.Popen('C:\\Users\\DAN\\Documents\\Fan\\HTFanControl.exe')

https://docs.python.org/3/library/subprocess.html
wouln't something like this be better?
python:
import subprocess
import xbmc

monitor = xbmc.Monitor()
try:
    with subprocess.Popen([r'C:\Users\DAN\Documents\Fan\HTFanControl.exe']) as proc:
        monitor.waitForAbort()
        proc.terminate()
except:
    xbmc.log('autoexec.py HTFanControl failed to run')

Haven't tried at all.  The idea is I assume HTFanControl doesn't terminate so Kodi hangs on exit until the addon gets killed.

scott s.
.
looks like it would be @scott967 i just left a simple example with the documentation so it could be expanded as needed.

i like yours as a much more complete example and manages the process closure as well

the initial example should run the program and not care about it after that, i dont believe kodi would hang because there is no wait

well done!
Thank you for also taking some interest in this scott967.

Neither of the two codes hang Kodi at exit.  Kodi has and still is exiting in about 3 seconds which sounds quick considering house cleaning duties.  Perhaps v21 has improved this.

Code by jepsizofye leaves the app open after Kodi has closed.
Code by scott967 shuts down the app after Kodi has closed.  
Both codes place an icon in the taskbar and the system tray.  I wish it didn't but isn't a big deal.

This app by SirMaster has always started with Windows and lived in the system tray only and it still does when I've adjusted it to start with Windows.  It's worked perfectly for years.
Some time ago, after the app started, it gave up connecting to my network.  I've spent days trying to figure out what changed its behavior and met with a dead end. 

I do know if I quit the app and restart it, it connects to my network no problem.  If I don't have the app start with Windows and wait a minute after booting before manually restarting it, it connects.  I can reboot several times and it will connect... as long as these subsequent reboots are back to back.  However, I shut down my PC at night for 12hrs or so.  Every morning when I cold start my PC, the app starts but isn't connected to my network again.  Closing it and restarting it connects every time.  Then I can reboot and it still connects... until it's been 12hrs or so.  So I gave up and don't have it start with Windows.  Only when Kodi starts which is the only time I use it anyway. 

I may ask SirMaster to delay the start with Windows for a minute or so because I believe this will fix my problem but I don't like to bother him.  If you're interested in what the app does - https://www.avsforum.com/threads/4d-thea...t.3152346/  This is a great addition for every home theater imo.  I like coding the WindTracks.

Thanks to both of you, my system remains completely automated from A-Z.  Really appreciate the help.

I should add, this app is designed to work with Kodi VideoPlayer (multi platforms), other front ends, and other players.
youre very welcome, happy to help
(2023-03-08, 05:54)brazen1 Wrote: [ -> ]Both codes place an icon in the taskbar and the system tray.  I wish it didn't but isn't a big deal.

You might be able to hide the Taskbar one, using search type select which icons appear on the taskbar see https://support.lenovo.com/jp/en/solutio...windows-10
First, I have no experience with this, just reading the man pages via google.

It seems like it might be possible to first get a subprocess.STARTUPINFO() object,
python:
su_info = subprocess.STARTUPINFO()
then try some of the settings available for that and pass the object as a keyword argument to Popen
python:
su_info.wShowWindow = subprocess.SW_HIDE
subprocess.Popen([args], startupinfo=su_info)
You would have to research/experiment.

scott s.
.
[font][font]Buenos dias, no llevo mucho tiempo con esto y tengo muchos problemas con la configuración de Kodi, error de registro es habitual, alguien sabe como solucionarlo ? perdonar si no es esta la página donde puedo preguntar.[/font][/font]