Nov-22-2018, 03:33 AM
(This post was last modified: Nov-22-2018, 03:57 AM by crustydave.)
Error 6 is invalid handle, however, the handle appears to be good, I believe the error is coming from the second parameter, if I make the pointer None, then it doesn't fail (but obviously doesn't do anything either).
C:\WINDOWS\system32>python -V
Python 3.6.6
I must be missing something obvious, but I don't see it. I tried different _pack_ to the structure, but with no improvement.
Thanks in advance,
-Dave
I should add that the service is actually running at this point, I just can't transition it out of Starting state with this issue.
C:\WINDOWS\system32>python -V
Python 3.6.6
#typedef struct _SERVICE_STATUS { # DWORD dwServiceType; # DWORD dwCurrentState; # DWORD dwControlsAccepted; # DWORD dwWin32ExitCode; # DWORD dwServiceSpecificExitCode; # DWORD dwCheckPoint; # DWORD dwWaitHint; #} SERVICE_STATUS, *LPSERVICE_STATUS; class _SERVICE_STATUS(Structure): #_pack_ = 4 _fields_ = [ ("dwServiceType", DWORD), ("dwCurrentState", DWORD), ("dwControlsAccepted", DWORD), ("dwWin32ExitCode", DWORD), ("dwServiceSpecificExitCode", DWORD), ("dwCheckPoint", DWORD), ("dwWaitHint", DWORD) ] LPSERVICE_STATUS = POINTER(_SERVICE_STATUS) global m_oServiceStatus m_oServiceStatus = _SERVICE_STATUS(0, 0, 0, 0, 0, 0, 0) def status_report(dwCurrentState, dwWin32ExitCode, dwWaitHint): global g_dwCheckPoint global g_isService global m_oServiceStatus try: # Fill in the SERVICE_STATUS structure. m_oServiceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS m_oServiceStatus.dwCurrentState = dwCurrentState m_oServiceStatus.dwWin32ExitCode = dwWin32ExitCode m_oServiceStatus.dwWaitHint = dwWaitHint if dwCurrentState == SERVICE_START_PENDING: m_oServiceStatus.dwControlsAccepted = 0 else: m_oServiceStatus.dwControlsAccepted = 1 if (dwCurrentState == SERVICE_STOPPED) or (dwCurrentState == SERVICE_RUNNING): m_oServiceStatus.dwCheckPoint = 0 else: g_dwCheckPoint += 1 m_oServiceStatus.dwCheckPoint = g_dwCheckPoint status = advapi32.SetServiceStatus(g_hServiceStatus, pointer(m_oServiceStatus)) if 0 == status: dwStatus = winKernel.GetLastError() #logging.info("SetServiceStatus(" + str(g_hServiceStatus) + ", status=" + str(dwStatus) + ")") logging.info("status_report(" + str(g_hServiceStatus) + ", " + str(dwCurrentState) + ", " + str(dwWin32ExitCode) + ", " + str(dwWaitHint) + ")") if g_isService: # Report the status of the service to the SCM. ptrServiceStatus = LPSERVICE_STATUS(m_oServiceStatus) logging.info("m_oServiceStatus struct: " + str(m_oServiceStatus) + ", ref: " + str(byref(m_oServiceStatus))) logging.info(" " + "ptr: " + str(str(pointer(m_oServiceStatus))) + " PTR: " + str(ptrServiceStatus)) status = advapi32.SetServiceStatus(g_hServiceStatus, pointer(m_oServiceStatus)) if 0 == status: dwStatus = winKernel.GetLastError() except Exception as e: exc_type, exc_obj, exc_tb = sys.exc_info() logging.error("status_report " + str(e) + " line: " + str(exc_tb.tb_lineno)) return dwStatus dwStatus = status_report(SERVICE_START_PENDING, NO_ERROR, 3000); logging.info("service_main: status_report(" + str(g_hServiceStatus) + "), status=" + str(dwStatus)) log_service_status(m_oServiceStatus)
Quote:INFO status_report(-842466752, 2, 0, 3000)
INFO m_oServiceStatus struct: <__main__._SERVICE_STATUS object at 0x000001EDCE0F55C8>, ref: <cparam 'P' (000001EDCE1389F0)>
INFO ptr: <__main__.LP__SERVICE_STATUS object at 0x000001EDCE0F57C8> PTR: <__main__.LP__SERVICE_STATUS object at 0x000001EDCE0F5748>
INFO service_main: status_report(-842466752), status=6
INFO 16, 2, 0, 0, 0, 1, 3000
I must be missing something obvious, but I don't see it. I tried different _pack_ to the structure, but with no improvement.
Thanks in advance,
-Dave
I should add that the service is actually running at this point, I just can't transition it out of Starting state with this issue.