show a windows form from a window service

前端 未结 3 1027
滥情空心
滥情空心 2020-12-02 02:32

i am creating a window service. my requirement is to display window form from window NT service on particular interval. For testing purpose , i just want to display the form

相关标签:
3条回答
  • Cant be done*. In later Operating Systems that won't work as Windows Services are disallowed from interacting with the Desktop - instead UI presented by Windows Services is shown in Session 0, a special logon session which is not normally visible to the end user.

    What you should instead do is write a separate Windows Forms application which is always running, but not always visible (possibly have that application run at startup and have an icon in the notification area) and communicates with the Windows Service using some form of IPC

    When the Windows Service wishes to display some UI to the user it sends a message to the application, which in turns shows the desired UI to the end user.

    **or at least it definitely shouldn't be done*

    0 讨论(0)
  • 2020-12-02 03:02

    Checking the "Interact with desktop" box will work on Windows NT, 2000, XP and 2003 but thanks to Session 0 Isolation that setting no longer works as you may expect in Windows Vista and beyond. You want to think very carefully before developing an interactive service...

    0 讨论(0)
  • 2020-12-02 03:14

    I am just referring to the answer given in another link in StackOverflow

    How to communicate with a windows service from an application that interacts with the desktop?

    Answer is :

    Be aware that if you are planning to eventually deploy on Windows Vista or Windows Server 2008, many ways that this can be done today will not work. This is because of the introduction of a new security feature called "Session 0 Isolation".

    Most windows services have been moved to run in Session 0 now in order to properly isolate them from the rest of the system. An extension of this is that the first user to login to the system no longer is placed in Session #0, they are placed in Session 1. And hence, the isolation will break code that does certain types of communication between services and desktop applications.

    The best way to write code today that will work on Vista and Server 2008 going forward when doing communication between services and applications is to use a proper cross-process API like RPC, Named Pipes, etc. Do not use SendMessage/PostMessage as that will fail under Session 0 Isolation.

    http://www.microsoft.com/whdc/system/vista/services.mspx

    Now, given your requirements, you are going to be in a bit of a pickle. For the cross-platform concerns, I'm not sure if Remoting would be supported. You may have to drop down and go all the way back to sockets: http://msdn.microsoft.com/en-us/library/system.net.sockets.aspx

    0 讨论(0)
提交回复
热议问题