qbittorrent / qBittorrent

qBittorrent BitTorrent client
https://www.qbittorrent.org
Other
28.1k stars 3.96k forks source link

'RunAs' is not properly supported on Windows #17675

Open andry81 opened 2 years ago

andry81 commented 2 years ago

qBittorrent & operating system versions

qBittorrent: 4.4.5 x64 Operating system: Windows 7 x64 (6.1.760x) Installer: qbittorrent_4.4.5_x64_setup.exe

What is the problem?

I want to run the app as a different or limited user. My current user is user and I use another user qb to run the app with: runas /user:qb <app>

This involves multiple issues:

  1. All file associations is under user because has been installed for it and click on any torrent file runs the app empty instance.
  2. If try to install directly with the arbitrary user runas /user:qb qbittorrent_4.4.5_x64_setup.exe
    RUNAS ERROR: Unable to run - qbittorrent_4.4.5_x64_setup.exe
    5: Access is denied.

I suggest several workarounds:

  1. Add to config the RunAs user to block app execution on any user other than that. Otherwise it starts and allocates configs for the current user.
  2. Reassign file associations for the arbitrary user:
    • Use runas.exe
      [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\qBittorrent\shell\open\command]
      @="runas.exe /user:qb \"\\\"C:\\Program Files\\qBittorrent\\qbittorrent.exe\\\" \\\"%1\\\"\""

      Or

    • Use a runner or a command line key specifically for that to internally run application by CreateProcessAsUser API:
      [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\qBittorrent\shell\open\command]
      @="\"C:\\Program Files\\qBittorrent\\qbittorrent.exe\" --run-as-user \"qb\" \"%1\""

      Or use with the environment variable:

      @="\"C:\\Program Files\\qBittorrent\\qbittorrent.exe\" --run-as-user \"%QBITTORRENT_RUN_AS_USER%\" \"%1\""

      Note: This will require a password input dialog.

  3. Add ability to the installer to install for a specific user including usage runas.exe or --run-as-user in the shortcuts.

Steps to reproduce

No response

Additional context

No response

Log(s) & preferences file(s)

No response

glassez commented 2 years ago

All file associations is under user because has been installed for it

It's correct behavior, isn't it?

2. If try to install directly with the arbitrary user runas /user:qb qbittorrent_4.4.5_x64_setup.exe

    RUNAS ERROR: Unable to run - qbittorrent_4.4.5_x64_setup.exe
    5: Access is denied.

Seems it is due the fact that user has no permissions to qbittorrent_4.4.5_x64_setup.exe or directory where it is located. It's your issue, not the installer's. Just put the installer where user can access it.

andry81 commented 2 years ago

Just put the installer where user can access it.

I've already did that. It runs w/o runas without an issue.

luzpaz commented 11 months ago

@glassez is this then still a valid issue ?

luzpaz commented 8 months ago

@andry81 can you still reproduce on latest stable (4.6.3) ?

andry81 commented 8 months ago

@andry81 can you still reproduce on latest stable (4.6.3) ?

@luzpaz Currently I don't have the environment. May be I can tell later when I have a time to test it.