[FIX] windows ctrl-c from cmd as a non admin
return False when calling is_running_as_nt_service from a non adminstrator account.
This commit is contained in:
parent
aa9eec3497
commit
fb9794835b
|
@ -26,7 +26,7 @@ if os.name == 'posix':
|
||||||
import resource
|
import resource
|
||||||
else:
|
else:
|
||||||
# Windows shim
|
# Windows shim
|
||||||
signal.SIGHUP = 0
|
signal.SIGHUP = -1
|
||||||
|
|
||||||
# Optional process names for workers
|
# Optional process names for workers
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -139,10 +139,13 @@ else:
|
||||||
finally:
|
finally:
|
||||||
ws.CloseServiceHandle(srv)
|
ws.CloseServiceHandle(srv)
|
||||||
|
|
||||||
|
try:
|
||||||
with close_srv(ws.OpenSCManager(None, None, ws.SC_MANAGER_ALL_ACCESS)) as hscm:
|
with close_srv(ws.OpenSCManager(None, None, ws.SC_MANAGER_ALL_ACCESS)) as hscm:
|
||||||
with close_srv(wsu.SmartOpenService(hscm, nt_service_name, ws.SERVICE_ALL_ACCESS)) as hs:
|
with close_srv(wsu.SmartOpenService(hscm, nt_service_name, ws.SERVICE_ALL_ACCESS)) as hs:
|
||||||
info = ws.QueryServiceStatusEx(hs)
|
info = ws.QueryServiceStatusEx(hs)
|
||||||
return info['ProcessId'] == getppid()
|
return info['ProcessId'] == getppid()
|
||||||
|
except Exception:
|
||||||
|
return False
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
from pprint import pprint as pp
|
from pprint import pprint as pp
|
||||||
|
|
Loading…
Reference in New Issue