mirror of
https://github.com/winsw/winsw.git
synced 2025-12-10 18:37:28 +08:00
Ensure we close correct handle after checking if service exists (#793)
Previously, this code would close the Service Control Manager (SCM) handle instead of the service handle, meaning: - any future calls to the SCM would fail due to invalid handle - a handle to the service was left open in error Also, reduce the access rights given to the handle, as we don't need ALL rights just to check if the service exists.
This commit is contained in:
@@ -164,13 +164,13 @@ namespace WinSW.Native
|
||||
|
||||
internal bool ServiceExists(string serviceName)
|
||||
{
|
||||
var serviceHandle = ServiceApis.OpenService(this.handle, serviceName, ServiceAccess.All);
|
||||
var serviceHandle = ServiceApis.OpenService(this.handle, serviceName, ServiceAccess.QueryStatus);
|
||||
if (serviceHandle == IntPtr.Zero)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_ = CloseServiceHandle(this.handle);
|
||||
_ = CloseServiceHandle(serviceHandle);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user