0

I have tried various solutions given in the links below to start, stop Windows Service (rabbitmq) in a PyTest without any admin rights prompt (so it can run continuously in a build server):

  1. os.system method --> The PyTest terminal asks for administrator password
  2. subprocess.run method --> I got Access Denied error message

Is it possible to start stop Windows service in the Pytest bypassing the admin rights? If yes, how can I do it?

Unknown
  • 778
  • 1
  • 7
  • 16
  • If reducing the security is an option for you you might lower UAC settings: https://learn.microsoft.com/en-us/windows/security/threat-protection/security-policy-settings/user-account-control-behavior-of-the-elevation-prompt-for-administrators-in-admin-approval-mode – An-dir May 07 '22 at 11:06
  • If that were possible, it would be a major security problem. Your process needs admin rights to do this. – MrBean Bremen May 07 '22 at 11:10
  • I just need to restart the Windows service in Pytest without the need to enter password or administrator prompt. Can I do it in Python code? – Unknown May 07 '22 at 11:11
  • @MrBeanBremen you are right. I ignored that He wrote "without any admin rights". – An-dir May 07 '22 at 11:56
  • 1
    @Unknown You might use "sc sdset servicename" to change permissions. The SDDL you need for that is a bit difficult but well described for example here: http://woshub.com/set-permissions-on-windows-service/ – An-dir May 07 '22 at 11:58
  • 1
    @An-dir, can you provide a solution from the example you provided? – Unknown May 07 '22 at 14:29
  • 1
    To clarify - the solution provided by @An-dir is to grant your user more rights (and it _is_ the solution, not an example). To do this, you need administrator rights, of course - there is no way to do this with standard user rights, otherwise the whole notion of administrator rights would be pointless. – MrBean Bremen May 08 '22 at 07:28

1 Answers1

1

This is not possible.

There is no current way to bypass those administrator permission known to me. Comments on your original question talked about the Service controller tool and modifying the SDDL of the corresponding service.

From what I've read here the command you need would be:

sc.exe sdset YourService "D:(A;;WPRP;;;WD)"

Replace "YourService" with your wanted service.

Do NOT paste this command as it would overwrite the whole SDDL, be sure to add it accordingly into your already existing SDDL to prevent system failure.

But, as mentioned before, you also do need Administrator priviliges to once set this. If it's set once and not reversed, every user on the PC has the right to start and stop the service.

Please remember that this makes the service vulnerable to any program.

(Sorry if I did anything wrong in explaining, this is my first ever answer on stackoverflow)

Drax
  • 11
  • 3