none
RegisterServiceCtrlHandlerEx Access denied RRS feed

  • Question

  • Hi,

    I am trying to do P-invoke to to RegisterServiceCtrlHandlerEx it fails, returns 0 which is invalid handle and the Marshal.GetLastWin32Error() returns 0xc0000005.

    Any idea? I have tried the same thing via C++ application, gives the same error.

    Venkat
    • Moved by Figo Fei Monday, June 23, 2008 3:07 AM move to CLR forum for answering
    Thursday, June 19, 2008 3:12 PM

Answers

  • Venkat, 

    I hope you have already resolved this but just in case you haven't and for the benefit of those to follow...

    I ran into the same problem: 0xc0000005 (acces violation) error running RegisterServiceCtrlHandlerEx.  I am getting this in C# using System.ServiceProcess.ServiceBase.  I resolved by moving RegisterServiceCtrlHandlerEx out of ServiceMain and into the OnStart override after running base.OnStart().  Apparently, the service is just not ready to change handlers until then. 

    Sunday, November 24, 2013 4:44 PM

All replies

  • Calling this API is only valid in the context for a service.  Even then you must not call it, the .NET ServiceBase class already does this for you.  Overriding its service control handler will render it inoperable.
    Hans Passant.
    Monday, June 23, 2008 9:37 AM
    Moderator
  • Please post the c++ code.

    You are calling RegisterServiceCtrlHandlerEx in your ServiceMain? with a correct pointer to the handlerex function?

    Thursday, June 26, 2008 2:07 PM
  • Venkat, 

    I hope you have already resolved this but just in case you haven't and for the benefit of those to follow...

    I ran into the same problem: 0xc0000005 (acces violation) error running RegisterServiceCtrlHandlerEx.  I am getting this in C# using System.ServiceProcess.ServiceBase.  I resolved by moving RegisterServiceCtrlHandlerEx out of ServiceMain and into the OnStart override after running base.OnStart().  Apparently, the service is just not ready to change handlers until then. 

    Sunday, November 24, 2013 4:44 PM