Home >Backend Development >C++ >How Can Non-Administrator Users Start and Stop Windows Services in C ?
Starting Windows Service from Application without Administrator Rights (C )
Question:
How can a user start or stop a Windows service from a non-administrator application without the need for administrator rights?
Answer:
To grant non-administrator users the ability to start and stop a Windows service, modify the service permissions. This process should ideally be performed during service installation.
Use the following steps:
<code class="pre">wchar_t sddl[] = L"D:" L"(A;;CCLCSWRPWPDTLOCRRC;;;SY)" // default permissions for local system L"(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)" // default permissions for administrators L"(A;;CCLCSWLOCRRC;;;AU)" // default permissions for authenticated users L"(A;;CCLCSWRPWPDTLOCRRC;;;PU)" // default permissions for power users L"(A;;RP;;;IU)" // added permission: start service for interactive users ;</code>
<code class="pre">PSECURITY_DESCRIPTOR sd; if (!ConvertStringSecurityDescriptorToSecurityDescriptor(sddl, SDDL_REVISION_1, &sd, NULL)) { fail(); } if (!SetServiceObjectSecurity(service, DACL_SECURITY_INFORMATION, sd)) { fail(); }</code>
To grant non-admin users the right to stop the service as well, include the WP right in the SDDL string:
<code class="pre">L"(A;;RPWP;;;IU)" // added permissions: start service, stop service for interactive users</code>
Refer to Wayne Martin's blog entry for additional SDDL codes for service rights.
The above is the detailed content of How Can Non-Administrator Users Start and Stop Windows Services in C ?. For more information, please follow other related articles on the PHP Chinese website!