Make Stop-Service only request needed privileges when not setting SDDL. (#16663)

* code changes to select permission based on input

* make the code more readable
This commit is contained in:
PRASOON KARUNAN V
2022-03-23 13:46:49 -07:00
committed by GitHub
parent 123373e425
commit 94eeb8e423
@@ -1756,10 +1756,14 @@ namespace Microsoft.PowerShell.Commands
return;
}
var access = NativeMethods.SERVICE_CHANGE_CONFIG;
if (!string.IsNullOrEmpty(SecurityDescriptorSddl))
access |= NativeMethods.WRITE_DAC | NativeMethods.WRITE_OWNER;
hService = NativeMethods.OpenServiceW(
hScManager,
Name,
NativeMethods.SERVICE_CHANGE_CONFIG | NativeMethods.WRITE_DAC | NativeMethods.WRITE_OWNER
access
);
if (hService == IntPtr.Zero)