hass-agent / HASS.Agent

Unofficial development project for the HASS.Agent platform.
https://hass-agent.io
MIT License
374 stars 9 forks source link

Bug: multi-user installation difficult, installation fails. #63

Closed PBrunot closed 1 month ago

PBrunot commented 8 months ago

Describe the bug Impossible to install the software as an unpriviledged (child) account. Installation and configuration on PC with multiple users is difficult. The reason I need that is that I have automation in HA to hibernate the PC if unused after a while, using last_active sensor. But this sensor stops being updated if the PC active user is not the installing user of HASS.Agent.

To Reproduce

  1. Install the agent as a priviledged user, configure autologon, and reboot.
  2. Logon as priviledged users, everything works.
  3. Logon as another user, the last update time sensor ceases to fire in HA (I guess because the agent profile runs in user session).
  4. So I try install the agent as the other user, but it requires admin priviledge.
  5. When I elevate the installer, it tries to write into priviledged_user\AppData\Local\HASS.Agent folder and fails.

Expected behavior Program should be installable with non-admin users.

Misc info (please complete the following information):

Please check what's applicable (multiple answers possible):

Additional context A workaround I found was to add full control priviledges on priviledged_user\AppData\Local\HASS.Agent for the other computer users. But the agents process seems to fight on MQTT server login. So I had to change MQTT user / clientid in the other user.

KohGeek commented 7 months ago

Question: I know this is not the intended purpose of the Satellite service, but have you tried configurating LastActive and Hibernate via the Satellite service?

Satellite service explicitly does not require user login, so I (personally) assume it would bypass these user account restrictions. At least hopefully that can serve as a temporary solution.

PBrunot commented 7 months ago

Good idea, but lastactive sensor is only available for hass.agent and not the satellite service. I guess it needs to monitor the active session. Not sure if there is a good way for a Service to monitor user activity inside multiple sessions.

KohGeek commented 7 months ago

Interesting, this is a note for the lead developer.

Currently the installer assume admin priviledge by default because it wants to install satellite service, by default.

Is it possible for the installer to make the satellite service optional, and then prompt for admin when satellite service installation is necessary?

Meanwhile, you can grab the non-installer version and launch it that way. I verified you don't need admin priviledge for it.

amadeo-alex commented 7 months ago

Definitely something that we need to look at, first and foremost "When I elevate the installer, it tries to write into priviledged_user\AppData\Local\HASS.Agent folder and fails" is not acceptable with the current idea that multiple users can have different HASS.Agent instances.

Is it possible for the installer to make the satellite service optional, and then prompt for admin when satellite service installation is necessary? Good idea, I'll take a look what kind of wiggle room Inno provides to us.

amadeo-alex commented 6 months ago

@PBrunot if you'd be willing to, I've created a test branch that separates the client/service installation - https://github.com/amadeo-alex/HASS.Agent/releases/tag/2.1.0-beta2-installer-redesign (Note: it's based on 2.1.0-beta2 branch so it also includes additional features/fixes) In theory this should be all to fix the mentioned use-cases - if not I'll work further on that.

Sorry that it took so long but there were other bugs like memory leak that we had to take care first.

PBrunot commented 6 months ago

Ok I will test it by end of the week, thank you.

PBrunot commented 6 months ago

Let me report by positive experience so far.

1) install

2) I switch to a non-admin account on same PC :

3) I switch back to the main account (without logging off)

4) I switch back to the non-admin account (without logging off)

5) I switch back to admin account (without logging off)

So in summary with 2 accounts (1 admin, 1 non-admin) on same Windows 11 machine I am able to run HASS agent with LastActive sensor in both accounts. The only minor inconvenience is that I have to generate differents HA token and Mosquitto usernames/passwords for each account on each computer.

I will test on another PC with 2 non-admin accounts + 1 admin account during the weekend.

amadeo-alex commented 6 months ago
i noticed that the service "HASS.Agent Satellite Service" was still present after uninstall

yeah, that's one of the bugs of original repo https://github.com/LAB02-Research/HASS.Agent/issues/366 you can use this to remove it manually (in administrative CMD):

sc delete "HASS.Agent Satellite Service"
SVNKoch commented 1 month ago

to give another 2cents:

Running on user account. Windows 10.

with 2.1.0 Beta4: Installation as user worked, currently testing the pplication. On first sight, seems to work as expected with the satelite running as admin.

with 2.0: opening the installer => elevation prompt installation directory: in admin account / appdata ... (changed it to c/programs)

after installation it didn't open automatically

opened it as admin going through configuration "will restart" => did not reopen

running as admin now => nothing happens