How to get the Handle for Windows Service? RRS feed

  • Question

  • Hi,


    I am trying to create a service for my windows application. The service would just call an application if it detects a USB device inserted on the computer. I want to register for device change notification to receive all the usb device event messages. In order to register for the devicechange I need to call the "HDEVNOTIFY RegisterDeviceNotification" function which takes in the service handle as one of its parameter. But using the Windows Service project in Visual Studio 2008, I cannot find anyway to get the handle. Can you please help.



    Akash Nemani


    Tuesday, April 13, 2010 2:25 AM

All replies

  • http://www.codeproject.com/KB/system/Windows_Services.aspx

    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful.
    Visual C++ MVP
    Tuesday, April 13, 2010 7:39 PM
  • I think ServiceController.ServiceHandle is the managed code way to do this, otherwise Win32 OpenService().

    On UAC systems I'm not sure your plan will work. Services cannot interact with the desktop, and firing off an application (by default running with the sysetm account) will not be able to access the desktop of the currently logged on user either. But that depends on exactly what "call an application" means.

    Phil Wilson
    Tuesday, April 13, 2010 7:41 PM