TechieGuy12 / PlexServerAutoUpdater

Automatically update Plex when running the Plex service.
MIT License
118 stars 10 forks source link

Auto-download relies on obsolete(?) registry keys existing #37

Open twon33 opened 4 years ago

twon33 commented 4 years ago

In order to get auto-downloads working with -silent, I needed to add the following REG_SZ values under HKCU\Software\Plex, Inc.\Plex Media Server:

LocalAppDataPath: "C:\Users\{username}\AppData\Local" ButlerUpdateChannel: "0"

It doesn't look like the obvious fallbacks are used (user's AppData\Local dir, public update channel) when those keys aren't present.

TechieGuy12 commented 4 years ago

I do get the LocalAppData folder for the user running Plex, so I'll see about falling back to that folder if the key isn't present.

AnthonyBe commented 4 years ago

Seeing same issue:

2020-02-12 18:41:52 Get the local data folder for Plex.
2020-02-12 18:41:52 Couldn't find the local data folder in the registry, so defaulting to the logged in user's local application data folder.
2020-02-12 18:41:52 Plex local data folder: C:\Users\Administrator\AppData\Local
2020-02-12 18:41:52 Verify the updates folder is specified.
2020-02-12 18:41:52 Getting ready to download the latest package.
2020-02-12 18:41:52 Checking for the latest version from Plex.
2020-02-12 18:41:52 The update channel is set for public.
2020-02-12 18:41:55 Parsing the information from Plex.
2020-02-12 18:41:55 The registry value from 'HKEY_USERS\S-1-5-21-1900099870-370164171-3406661603-500\SOFTWARE\Plex, Inc.\Plex Media Server\\LocalAppDataPath' could not be retrieved. Verify that the registry value exists.
2020-02-12 18:41:55 The path to the local downloaded install file could not be determined.
2020-02-12 18:41:55 The latest available installation could not be downloaded.
2020-02-12 18:41:55 Verify the updates folder, C:\Users\Administrator\AppData\Local\Plex Media Server\Updates exists.
2020-02-12 18:41:55 Checking to see if updates folder exists.
2020-02-12 18:41:55 Updates folder does not exist. Looks like a new install.
2020-02-12 18:41:55 Displaying the update window.
2020-02-12 18:51:49 Closing the application.

I can confirm that the LocalAppDataPath registry value does not exist on my Plex Server PC

Is manually adding the LocalAppDataPath: "C:\Users\{username}\AppData\Local" value really required or is there a neater way to have this work?

TechieGuy12 commented 4 years ago

This is something I have seen with Plex in the past. There is usually a set of registry keys used by Plex where it stores the settings from the Plex server GUI, but sometimes it doesn't have those registry keys, I'm not sure why, maybe if the settings aren't changed. For me, I don't run Plex as an admin, so I had to manually copy the keys from the admin account (which was used to install and initially run Plex) to the account that runs the Plex service.

I'm not sure if Plex stores this value elsewhere on the system - if it does then I could use that. An alternative in the meantime is to see about defaulting to the application path of the user that runs the service.

AnthonyBe commented 4 years ago

Out of curiosity, I downloaded an update through the Plex app and then manually re-ran psupdate just to see what would happen, it got further, but still ultimately bombed out.

Note: I had not manually added the LocalAppDataPath registry value yet.

2020-02-25 20:28:24 Getting windows user.
2020-02-25 20:28:25 Checking if user is an administrator.
2020-02-25 20:28:25 Initializing the update window.
2020-02-25 20:28:25 Initializing the timer object.
2020-02-25 20:28:25 Initializing the Plex media server object.
2020-02-25 20:28:31 Getting the service user.
2020-02-25 20:28:31 The Plex service is installed. Let's get the user associated with the service.
2020-02-25 20:28:33 The Plex service user: ANTMICROSERVER\Administrator.
2020-02-25 20:28:33 Get the local data folder for Plex.
2020-02-25 20:28:33 Couldn't find the local data folder in the registry, so defaulting to the logged in user's local application data folder.
2020-02-25 20:28:33 Plex local data folder: C:\Users\Administrator\AppData\Local
2020-02-25 20:28:34 Verify the updates folder is specified.
2020-02-25 20:28:34 Getting ready to download the latest package.
2020-02-25 20:28:34 Checking for the latest version from Plex.
2020-02-25 20:28:34 The update channel is set for public.
2020-02-25 20:28:38 Parsing the information from Plex.
2020-02-25 20:28:39 The registry value from 'HKEY_USERS\S-1-5-21-1900099870-370164171-3406661603-500\SOFTWARE\Plex, Inc.\Plex Media Server\\LocalAppDataPath' could not be retrieved. Verify that the registry value exists.
2020-02-25 20:28:39 The path to the local downloaded install file could not be determined.
2020-02-25 20:28:39 The latest available installation could not be downloaded.
2020-02-25 20:28:39 Verify the updates folder, C:\Users\Administrator\AppData\Local\Plex Media Server\Updates exists.
2020-02-25 20:28:39 Checking to see if updates folder exists.
2020-02-25 20:28:39 Getting the latest update folder.
2020-02-25 20:28:39 Checking for the latest Plex packages folder.
2020-02-25 20:28:39 Get the latest packages file.
2020-02-25 20:28:39 Latest packages file: C:\Users\Administrator\AppData\Local\Plex Media Server\Updates\1.18.7.2457-77cb9455c\packages\PlexMediaServer-1.18.7.2457-77cb9455c-x86.exe
2020-02-25 20:28:39 The server is not in use continuing to perform the update.
2020-02-25 20:28:39 Displaying the update window.
2020-02-25 20:30:55 The server is not in use continuing to perform the update.
2020-02-25 20:30:55 START: Stopping the Plex service.
2020-02-25 20:30:57 END: Stopping the Plex service.
2020-02-25 20:30:57 START: Stopping the Plex Server processes.
2020-02-25 20:30:57 Stopping the Plex Media Server processes.
2020-02-25 20:30:57 Stopping Plex Media Server.exe processes.
2020-02-25 20:30:57 Message:
One or more errors occurred.

Inner Exception:
System.ComponentModel.Win32Exception (0x80004005): Access is denied
   at System.Diagnostics.Process.Kill()
   at TE.Plex.MediaServer.StopProcess(String processName)
   at TE.Plex.MediaServer.StopProcesses()
   at TE.Plex.MediaServer.Update()
   at TE.Plex.MainForm.<>c__DisplayClass17_0.<PerformUpdate>b__0()
   at System.Threading.Tasks.Task.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()

Stack Trace:
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at TE.Plex.MainForm.PerformUpdate()
2020-02-25 20:30:57 Initializing the timer object.
2020-02-25 20:30:57 Initializing the Plex media server object.
2020-02-25 20:30:57 Getting the service user.
2020-02-25 20:30:57 The Plex service is installed. Let's get the user associated with the service.
2020-02-25 20:30:58 The Plex service user: ANTMICROSERVER\Administrator.
2020-02-25 20:30:58 Get the local data folder for Plex.
2020-02-25 20:30:58 Couldn't find the local data folder in the registry, so defaulting to the logged in user's local application data folder.
2020-02-25 20:30:58 Plex local data folder: C:\Users\Administrator\AppData\Local
2020-02-25 20:30:58 Verify the updates folder is specified.
2020-02-25 20:30:58 Getting ready to download the latest package.
2020-02-25 20:30:58 Checking for the latest version from Plex.
2020-02-25 20:30:58 The update channel is set for public.
2020-02-25 20:31:01 Parsing the information from Plex.
2020-02-25 20:31:01 The registry value from 'HKEY_USERS\S-1-5-21-1900099870-370164171-3406661603-500\SOFTWARE\Plex, Inc.\Plex Media Server\\LocalAppDataPath' could not be retrieved. Verify that the registry value exists.
2020-02-25 20:31:01 The path to the local downloaded install file could not be determined.
2020-02-25 20:31:01 The latest available installation could not be downloaded.
2020-02-25 20:31:01 Verify the updates folder, C:\Users\Administrator\AppData\Local\Plex Media Server\Updates exists.
2020-02-25 20:31:01 Checking to see if updates folder exists.
2020-02-25 20:31:01 Getting the latest update folder.
2020-02-25 20:31:01 Checking for the latest Plex packages folder.
2020-02-25 20:31:01 Get the latest packages file.
2020-02-25 20:31:01 Latest packages file: C:\Users\Administrator\AppData\Local\Plex Media Server\Updates\1.18.7.2457-77cb9455c\packages\PlexMediaServer-1.18.7.2457-77cb9455c-x86.exe

It's quite odd because at first it says that it can't find the path, and then it finds the path and the update package?

AnthonyBe commented 4 years ago

So, I've now added the LocalAppDataPath registry value. Everything progressed nicely until it got to the actual updating part.. and then just hung/died.

2020-02-25 20:42:34 Getting windows user.
2020-02-25 20:42:34 Checking if user is an administrator.
2020-02-25 20:42:34 Initializing the update window.
2020-02-25 20:42:34 Initializing the timer object.
2020-02-25 20:42:34 Initializing the Plex media server object.
2020-02-25 20:42:34 Getting the service user.
2020-02-25 20:42:34 The Plex service is installed. Let's get the user associated with the service.
2020-02-25 20:42:35 The Plex service user: ANTMICROSERVER\Administrator.
2020-02-25 20:42:35 Get the local data folder for Plex.
2020-02-25 20:42:35 Plex local data folder: C:\Users\Administrator\AppData\Local
2020-02-25 20:42:35 Verify the updates folder is specified.
2020-02-25 20:42:35 Getting ready to download the latest package.
2020-02-25 20:42:35 Checking for the latest version from Plex.
2020-02-25 20:42:35 The update channel is set for public.
2020-02-25 20:42:37 Parsing the information from Plex.
2020-02-25 20:42:37 The file, C:\Users\Administrator\AppData\Local\Plex Media Server\Updates\1.18.7.2457-77cb9455c\packages\PlexMediaServer-1.18.7.2457-77cb9455c-x86.exe, exists. Checking to see if the package is valid.
2020-02-25 20:42:38 Checking if the installation package is valid.
2020-02-25 20:42:38 The package is valid. The checksums match.
2020-02-25 20:42:38 Since the package is valid - not downloading again.
2020-02-25 20:42:38 Verify the updates folder, C:\Users\Administrator\AppData\Local\Plex Media Server\Updates exists.
2020-02-25 20:42:38 Checking to see if updates folder exists.
2020-02-25 20:42:38 Getting the latest update folder.
2020-02-25 20:42:38 Checking for the latest Plex packages folder.
2020-02-25 20:42:38 Get the latest packages file.
2020-02-25 20:42:38 Latest packages file: C:\Users\Administrator\AppData\Local\Plex Media Server\Updates\1.18.7.2457-77cb9455c\packages\PlexMediaServer-1.18.7.2457-77cb9455c-x86.exe
2020-02-25 20:42:38 The server is not in use continuing to perform the update.
2020-02-25 20:42:38 Displaying the update window.
2020-02-25 20:43:20 The server is not in use continuing to perform the update.
2020-02-25 20:43:20 START: Stopping the Plex service.

Just for reference this is running on Windows Server 2012 R2 and I'm logged in with the local Administrator account performing this via RDP session.

nisola-c4 commented 4 years ago

I had to add the LocalAppDataPath key as well in order to get the program to recognize there was an update available, but did not have any issues after adding that key. I run Plex as administrator on a Server 2019 install.

theg1nger commented 4 years ago

@funnyfarm299 Thanks!

Log file had the same error in it: 2020-06-05 12:41:40 The registry value from 'HKEY_USERS\XXXXXXXXXXXXXXXXXXXX\SOFTWARE\Plex, Inc.\Plex Media Server\\LocalAppDataPath' could not be retrieved. Verify that the registry value exists.

I looked for the LocalAppdataPath key and did not find it. Adding a String of LocalAppDataPath to: Computer\HKEY_USERS\XXXXXXXXXXXXXXXXXXXX\Software\Plex, Inc.\Plex Media Server with a value of C:\Users\XXXX\AppData\Local\Plex Media Server is what fixed it for me.

Update: The above actually caused plex to be un-useable. I removed the reg entry, restarted, and everything went back to normal. YMMV