mirror of https://github.com/winsw/winsw
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.pull/794/head
parent
8b8d983b51
commit
80ec5356cc
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue