locked
sendwait not working in windows service RRS feed

  • Question

  • Hi all,

    I have made WCF service library to generate key event. Below is the code.

    trace.WriteLine("inside WCF Service with key: " + keyCode);
            trace.Flush();
            SendKeys.SendWait(keyCode);
            SendKeys.Flush();
            trace.WriteLine("Key Sent");
            trace.Flush();

    Later I developed a client for this service. If I am running the service from visual studio it's working fine and active window is getting the key event. If I host it in windows service and use the same clien it's not working. Even in the case of windows service call is getting delegated to above function and I am getting the trace. Please help me in this regard. Thanks in advance.

     

    PS: I am running it in XP, so there is no chance of session zero isolation.

    Tuesday, May 31, 2011 3:00 AM

Answers

  • Hello, basically you should not interact with UI in a Windows Service. If you have to, please use a standard application instead of a Windows Service. Since you're using Windows XP, there was a workaround to enable the interaction by checking "Allow service to interact with desktop" option. But please note it is not recommended to use that option, and later versions of Windows no longer support it.

    By the way, why do you need to send key events from a service to a UI application? Even if you use a standard application to host the service, it won't work unless the client and the service are on the same machine.


    Lante, shanaolanxing This posting is provided "AS IS" with no warranties, and confers no rights.
    Windows Azure Technical Forum Support Team Blog
    Wednesday, June 1, 2011 2:26 AM

All replies

  • Hello, basically you should not interact with UI in a Windows Service. If you have to, please use a standard application instead of a Windows Service. Since you're using Windows XP, there was a workaround to enable the interaction by checking "Allow service to interact with desktop" option. But please note it is not recommended to use that option, and later versions of Windows no longer support it.

    By the way, why do you need to send key events from a service to a UI application? Even if you use a standard application to host the service, it won't work unless the client and the service are on the same machine.


    Lante, shanaolanxing This posting is provided "AS IS" with no warranties, and confers no rights.
    Windows Azure Technical Forum Support Team Blog
    Wednesday, June 1, 2011 2:26 AM
  • Hi,

    This is the our project requirement. My application will get a message and correspondingly it will send key event to active window. But I want it to run like backend process.

    Wednesday, June 1, 2011 3:40 AM
  • Hey,

    It worked, but what you said was very much correct. Now I will be making another application which will run in background and will use windows service to launch my application.

    Thanks

    Wednesday, June 1, 2011 4:21 AM