How to close an application from a service?

잠김 How to close an application from a service?

  • 25. července 2012 6:08
     
     

    Hi there,

    I have a service which resides in session 0.

    I can create a process (a WinForm application) in user session by calling CreateProcessAsUser(...).

    In some situation, I need to close the process created by my service, so I call TerminateProcess(...) to close it.

    However, the process has no change to release its resource if I call TerminateProcess(...) from my service.

    Is there any solution to close a process from a service and the process can release its resource?

    Thanks in advance.

Všechny reakce

  • 25. července 2012 8:18
     
     Odpovědět

    If you have access to the source code of the Winform application you could establish an IPC mechanism, your service and your GUI application communicate usingthis mechanism. You can than tell the winform application that the application has to be terminated. That is a clean and safe way.

    In the windows SDK you will find an example under "Samples\winbase\service". This example contains a small windows service and a client application. both are communicating using pipes.

    • Označen jako odpověď JupiterLee 25. července 2012 12:59
    •