none
How can I P/Invoke from a System service to a process running under a user account? RRS feed

  • Question

  • I have a service that needs to communicate with another process that is running under a user account, not as a service. When I'm testing my program as a normal process I can P/Invoke the COM call just fine, but when I run my program as a service then the P/Invoke fails.

    Is it possible to P/Invoke from a service to a program running under a user account? If so, how?

    I've tried a few things already:
    1. I tried impersonating the user that is running the other program from my service and then do the P/Invoke, but this didn't help.
    2. I tried running my service as the other user account instead of as SYSTEM, but then I ran into a different issue. My service must interact with the desktop, and when running as SYSTEM there is an option to do this, but when running as the other account this didn't work.
    If this isn't possible, then what other options do I have? One that I've considered is creating a small program that I can run under the user account that responds to a named pipe and then does the P/Invoke from there.
    Monday, March 9, 2009 9:29 AM

Answers

  • Well, technically you could have the service load the user's profile (do a full login) instead of impersonating.

    However, it's best if you run it as the other user and separate the GUI from your service. Every release of Microsoft's OS tightens the restrictions on services with GUIs, and they'll probably be flat-out disallowed a few years from now.

            -Steve
    • Marked as answer by Zhi-Xin Ye Friday, March 13, 2009 3:23 AM
    Monday, March 9, 2009 6:47 PM

All replies

  • Well, technically you could have the service load the user's profile (do a full login) instead of impersonating.

    However, it's best if you run it as the other user and separate the GUI from your service. Every release of Microsoft's OS tightens the restrictions on services with GUIs, and they'll probably be flat-out disallowed a few years from now.

            -Steve
    • Marked as answer by Zhi-Xin Ye Friday, March 13, 2009 3:23 AM
    Monday, March 9, 2009 6:47 PM
  • Thanks for the reply.

    For now I think we try running it as as a normal program via the Startup menu. The main reason we were running it as a service was to get the failure/restart protection that provides.
    Tuesday, March 10, 2009 7:31 AM