microsoft:scripting:batchfiles:allowusertostopandstartservice
Microsoft - Scripting - Batch Files - Allow user to stop and start service
Tested on Windows Server 2016.
- Open an elevated command prompt.
- Check the current SDDL on the service:
"%SYSTEMROOT%\system32\sc.exe" sdshow "Spooler"
- Output should look like:
D:(A;;CCLCSWLOCRRC;;;AU)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWRPWPDTLOCRRC;;;SY)S:(AU;FA;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;WD)
- Use PowerShell to get the SID of the account that should be able to stop/start the service:
- For an Active Directory account:
Get-ADUser service_account -Properties objectSid | Select-Object objectSid
- For a local account:
Get-LocalUser service_account | Select-Object Name,SID
- Add the SID of the Active Directory account at the end of the D:-part of the SDDL of the service with LC (query status), RP (start), WP (stop), and DT (pause/continue) permissions:
D:(A;;CCLCSWLOCRRC;;;AU)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;LCRPWPDT;;;S-1-5-21-XXXXXXXXXX-XXXXXXXXXX-XXXXXXXXXX-1127)S:(AU;FA;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;WD)
- Apply the new SDDL to the service:
"%SYSTEMROOT%\system32\sc.exe" sdset "Spooler" D:(A;;CCLCSWLOCRRC;;;AU)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;LCRPWPDT;;;S-1-5-21-XXXXXXXXXX-XXXXXXXXXX-XXXXXXXXXX-1127)S:(AU;FA;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;WD)
Sources:
- serverfault - how to set permissions on a service This suggests to use RPWPDTLO as permission set, but I found that with LO I could start the service from a cmd.exe running as the service account, but got an access denied when trying to start the service from a batch file running in a scheduled task under the service account. Using LCRPWPDT seems to fix this.
microsoft/scripting/batchfiles/allowusertostopandstartservice.txt · Last modified: 2024/05/22 11:02 by bas