# PlexConnect as Windows Service

**URL:** <https://forums.plex.tv/t/plexconnect-as-windows-service/57594>\
**Category:** Apps & Creations\
**Created:** [February 16, 2014, 4:27am UTC](https://forums.plex.tv/t/plexconnect-as-windows-service/57594 "2014-02-16T04:27:43Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![halfluck](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/halfluck/32/98588_2.png) [@halfluck](https://forums.plex.tv/u/halfluck)\
**Post date:** [February 16, 2014, 4:27am UTC](https://forums.plex.tv/t/plexconnect-as-windows-service/57594/1 "2014-02-16T04:27:43Z")

</div>

**EDIT: Full instructions for PlexConnect as a windows service can now be found on [this wiki page](https://github.com/iBaa/PlexConnect/wiki/Win-autostart).**

&nbsp;

Hey Guys,

&nbsp;

For those that haven't seen this yet, It works really well! nice work to those involved :rolleyes:

&nbsp;

If you grab the [latest git](https://github.com/iBaa/PlexConnect/archive/master.zip) and install [pywin32](http://sourceforge.net/projects/pywin32/) you can run PlexConnect as a service on windows

startup.

&nbsp;

i'm just using the Task Scheduler to grab the latest git and then start the service (i assume this is the best way?)

&nbsp;

start-plexconnect.bat

```
C:
cd \plexconnect
git pull
python PlexConnect_Winservice.py start
```

Cheers Rob.

---

<div class="post-metadata">

**Author:** ![baa](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/baa/32/2026_2.png) [@baa](https://forums.plex.tv/u/baa)\
**Post date:** [February 16, 2014, 8:42am UTC](https://forums.plex.tv/t/plexconnect-as-windows-service/57594/2 "2014-02-16T08:42:35Z")

</div>

While testing, I still see issues like ATVSettings.cfg not being saved at shutdown...

Not sure, why that happens (or not...).

---

<div class="post-metadata">

**Author:** ![halfluck](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/halfluck/32/98588_2.png) [@halfluck](https://forums.plex.tv/u/halfluck)\
**Post date:** [February 16, 2014, 11:17am UTC](https://forums.plex.tv/t/plexconnect-as-windows-service/57594/3 "2014-02-16T11:17:31Z")

</div>

Ahh I see, perhaps when it saves incrementally that won’t be such an issue.  
  
  
Would you need to stop the service manually on a shutdown/reboot to save settings otherwise?

---

<div class="post-metadata">

**Author:** ![baa](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/baa/32/2026_2.png) [@baa](https://forums.plex.tv/u/baa)\
**Post date:** [February 16, 2014, 11:56am UTC](https://forums.plex.tv/t/plexconnect-as-windows-service/57594/4 "2014-02-16T11:56:11Z")

</div>

Well, that's the thing. With manual stop/start the file is updated correctly. I don't know what Windows does differently, when the service is stopped caused by a shutdown...

The goal is, to NOT have the need to do it manually.

---

<div class="post-metadata">

**Author:** ![roidy](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/roidy/32/128627_2.png) [@roidy](https://forums.plex.tv/u/roidy)\
**Post date:** [February 16, 2014, 12:35pm UTC](https://forums.plex.tv/t/plexconnect-as-windows-service/57594/5 "2014-02-16T12:35:05Z")

</div>

How do you uninstall the service?

---

<div class="post-metadata">

**Author:** ![halfluck](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/halfluck/32/98588_2.png) [@halfluck](https://forums.plex.tv/u/halfluck)\
**Post date:** [February 16, 2014, 12:38pm UTC](https://forums.plex.tv/t/plexconnect-as-windows-service/57594/6 "2014-02-16T12:38:32Z")

</div>

Hey Roidy,

There is a batch file included on the git for install/start/stop/uninstall

(support/win/uninstall.bat) is the one you are after....

```
@echo off
set InstallerPath=%~dp0
set PlexConnectPath=%InstallerPath%..\..\
python %PlexConnectPath%PlexConnect_WinService.py remove
echo PlexConnect-Service removed
```

&nbsp;

---

<div class="post-metadata">

**Author:** ![roidy](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/roidy/32/128627_2.png) [@roidy](https://forums.plex.tv/u/roidy)\
**Post date:** [February 16, 2014, 12:43pm UTC](https://forums.plex.tv/t/plexconnect-as-windows-service/57594/7 "2014-02-16T12:43:56Z")

</div>

Ok, I'm not using the batch files and I&nbsp;assumed it would be:-&nbsp;

```
python PlexConnect_Winservice.py uninstall
```

That'll teach me to read the file notes :D  
&nbsp;

---

<div class="post-metadata">

**Author:** ![NiTruS](https://avatars.discourse-cdn.com/v4/letter/n/8e7dd6/32.png) [@NiTruS](https://forums.plex.tv/u/NiTruS)\
**Post date:** [February 16, 2014, 2:04pm UTC](https://forums.plex.tv/t/plexconnect-as-windows-service/57594/8 "2014-02-16T14:04:30Z")

</div>

this does not work on win 8.1…  
  
  
edit: after removing the beginning ‘python’ on all 4 bat files, it works fine…  
  
weird how python wasnt recognized, even though its installed…  
  
  
fyi…creating a shortcut to PlexConnect.py & placing this in startup folder/run minimized, also works…  
  
this is how i was starting plexconnect until now…thanks for that 🙂

---

<div class="post-metadata">

**Author:** ![baa](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/baa/32/2026_2.png) [@baa](https://forums.plex.tv/u/baa)\
**Post date:** [February 16, 2014, 4:13pm UTC](https://forums.plex.tv/t/plexconnect-as-windows-service/57594/9 "2014-02-16T16:13:03Z")

</div>

Python is found by either the file type (.py) or the first line within PlexConnect.py (#!/usr/bin/env python).

Do you know, why it won't work on your machine? What happens when typing "python" in a cmd window?

---

<div class="post-metadata">

**Author:** ![roidy](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/roidy/32/128627_2.png) [@roidy](https://forums.plex.tv/u/roidy)\
**Post date:** [February 16, 2014, 4:33pm UTC](https://forums.plex.tv/t/plexconnect-as-windows-service/57594/10 "2014-02-16T16:33:41Z")

</div>

He probably doesn’t have python added to his path Environment Variables, but does have the .py file association.

---

<div class="post-metadata">

**Author:** ![NiTruS](https://avatars.discourse-cdn.com/v4/letter/n/8e7dd6/32.png) [@NiTruS](https://forums.plex.tv/u/NiTruS)\
**Post date:** [February 16, 2014, 4:35pm UTC](https://forums.plex.tv/t/plexconnect-as-windows-service/57594/11 "2014-02-16T16:35:16Z")

</div>

Microsoft Windows [Version 6.3.9600]  
  
© 2013 Microsoft Corporation. All rights reserved.  
  
  
C:\WINDOWS\system32\>python  
  
‘python’ is not recognized as an internal or external command,  
  
operable program or batch file.  
  
  
C:\WINDOWS\system32\>  
  
  
if i remove ‘python’ it works…i dont need python in front of the command below…  
  
  
%PlexConnectPath%PlexConnect\_WinService.py install

---

<div class="post-metadata">

**Author:** ![roidy](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/roidy/32/128627_2.png) [@roidy](https://forums.plex.tv/u/roidy)\
**Post date:** [February 16, 2014, 6:22pm UTC](https://forums.plex.tv/t/plexconnect-as-windows-service/57594/12 "2014-02-16T18:22:59Z")

</div>

Open any windows explorer and right click on “Computer” in the left hand side of explorer. Select “Properties” from the menu. This will bring up the system information windows, on the left hand side press “Advanced system settings”. This should launch a windows with the “Advanced” tab already selected, at the bottom press the “Enviroment Variables” button. At the bottom of the next windows is a scroll list called “System Variables”, scroll down the list to find the entry called “Path”, click to highlight it, press “Edit”. DO NOT DELETE THE CONTENT OF “Variable Value” instead add the following to the end:-  
  
;c:\Python27;  
  
Replacing the above path with where ever you installed python. “OK” out of all the dialogs and reboot your computer. Try running python again from a command prompt.  
  
Or just edit python out of all the batch files 🙂

---

<div class="post-metadata">

**Author:** ![baa](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/baa/32/2026_2.png) [@baa](https://forums.plex.tv/u/baa)\
**Post date:** [February 16, 2014, 8:56pm UTC](https://forums.plex.tv/t/plexconnect-as-windows-service/57594/13 "2014-02-16T20:56:28Z")

</div>

Question - the filetype settings (i.e. which executable to launch for a given file) are user dependent, right?

When does the "service" start running, with windows starting up (that's how it should work...) - or later, when logging in?

-\> I think the filetype dependency wouldn't fly in that case...

The PATH to python however should be a system-wide setting.

I might be wrong, only "play" with windows, when I really have to - mostly during day job hours, those long ones. :-)

---

<div class="post-metadata">

**Author:** ![baa](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/baa/32/2026_2.png) [@baa](https://forums.plex.tv/u/baa)\
**Post date:** [February 20, 2014, 4:42pm UTC](https://forums.plex.tv/t/plexconnect-as-windows-service/57594/14 "2014-02-20T16:42:26Z")

</div>

> Well, that's the thing. With manual stop/start the file is updated correctly. I don't know what Windows does differently, when the service is stopped caused by a shutdown...
> 
> The goal is, to NOT have the need to do it manually.

We had a recent bugfix in this area:  
[fix broken shutdown - missed return value from run()](https://github.com/iBaa/PlexConnect/commit/de69eacc840fc3ec17ab618470acc2583a17f8fc)

Can anybody verify that this helps the Service shutdown as well?

---

<div class="post-metadata">

**Author:** ![simplify](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@simplify](https://forums.plex.tv/u/simplify)\
**Post date:** [February 21, 2014, 1:53pm UTC](https://forums.plex.tv/t/plexconnect-as-windows-service/57594/15 "2014-02-21T13:53:25Z")

</div>

I made a small change the the installation script below - address' the python not found issue... &nbsp;

```
@echo off

set InstallerPath=%~dp0  
set PlexConnectPath=%InstallerPath%…  
if “%PROCESSOR\_ARCHITECTURE%”==“AMD64” goto x64  
Set PythonPath=C:\Program Files\Python27  
goto install  
:x64  
Set PythonPath=C:\Program Files (x86)\Python27  
goto install

:install  
“%PythonPath%python” “%PlexConnectPath%PlexConnect\_WinService.py” install  
cls  
echo PlexConnect-Service installed!  
pause
```

Hope this helps people out...

Baa you are welcome to include this in future updates if you like.

Also if you want to detect if running on a Windows DC that has DNS running and want to disable DNS service so that PlexConnect runs correctly....

```
@echo off
cls
sc query "DNS" | find "RUNNING" >1
if "%ERRORLEVEL%"=="0" (
    sc stop DNS
	sc config DNS start=disabled
	echo DNS is now stopped and disabled!
) else (
    echo DNS is not running.
) 
```

this one needs elevated privileges to run correctly.

---

<div class="post-metadata">

**Author:** ![baa](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/baa/32/2026_2.png) [@baa](https://forums.plex.tv/u/baa)\
**Post date:** [February 21, 2014, 3:39pm UTC](https://forums.plex.tv/t/plexconnect-as-windows-service/57594/16 "2014-02-21T15:39:23Z")

</div>

\>\>PythonPath

How high is the risk the your two directories won't fit the bill? My opinion: very high. I don't think that we should set environment variables that we have no background in defining...

Good that you already fixed the IF-else-stucture. :-)

\>\>DNS

I don't think other will be happy with that. In the end you cancel out their main DNS, leaving them somewhat alone, even killing the chance that a reboot might fix things.

---

<div class="post-metadata">

**Author:** ![bakman1](https://avatars.discourse-cdn.com/v4/letter/b/c89c15/32.png) [@bakman1](https://forums.plex.tv/u/bakman1)\
**Post date:** [February 21, 2014, 6:36pm UTC](https://forums.plex.tv/t/plexconnect-as-windows-service/57594/17 "2014-02-21T18:36:44Z")

</div>

This stuff doesn't seem to work in my win7 environment:

```
set InstallerPath=%~dp0
set PlexConnectPath=%InstallerPath%..\..\
```

```
C:\Program Files (x86)\PlexConnect\support\Win>stop.bat
python: can't open file 'C:\Program': [Errno 2] No such file or directory
```

**edit&nbsp;** I think the path should be enclosed in quotes;&nbsp;then it works

```
python "%PlexConnectPath%PlexConnect_WinService.py" stop
```

---

<div class="post-metadata">

**Author:** ![simplify](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@simplify](https://forums.plex.tv/u/simplify)\
**Post date:** [February 22, 2014, 4:23am UTC](https://forums.plex.tv/t/plexconnect-as-windows-service/57594/18 "2014-02-22T04:23:04Z")

</div>

> \>\>PythonPath  
> How high is the risk the your two directories won't fit the bill? My opinion: very high. I don't think that we should set environment variables that we have no background in defining...  
> Good that you already fixed the IF-else-stucture. :-)  
>   
> \>\>DNS  
> I don't think other will be happy with that. In the end you cancel out their main DNS, leaving them somewhat alone, even killing the chance that a reboot might fix things.

  
Fair enough. Just trying to offer some further help for other that may have had the same problem as me...   
  
And of course in regards to the DNS changes - you don't have to run it or you can modify it to not disable the DNS.   
  
I will shut up now.   
  
  
Sent from my iPad using Tapatalk

---

<div class="post-metadata">

**Author:** ![baa](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/baa/32/2026_2.png) [@baa](https://forums.plex.tv/u/baa)\
**Post date:** [February 22, 2014, 7:25am UTC](https://forums.plex.tv/t/plexconnect-as-windows-service/57594/19 "2014-02-22T07:25:45Z")

</div>

\>\>I will shut up now.

Oh no, wrong decision. :-)

You can have your free&nbsp;speech, I didn't want to shoot down your creativity and/or opinion.

I just think, those issues I wrote about need at least some thoughts/discussion...

---

<div class="post-metadata">

**Author:** ![baa](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/baa/32/2026_2.png) [@baa](https://forums.plex.tv/u/baa)\
**Post date:** [February 22, 2014, 7:27am UTC](https://forums.plex.tv/t/plexconnect-as-windows-service/57594/20 "2014-02-22T07:27:14Z")

</div>

\>\>I think the path should be enclosed in quotes;&nbsp;then it works

Ok, I will change that on github. Always the same, stumbling over this "late to the game" change of handling SPACEs in path/file names.

[Next page](https://forums.plex.tv/t/plexconnect-as-windows-service/57594.md?page=2)
