Solved

Using ::PostMessage and ::SendInput in a Service

Posted on 2003-11-12
5
1,337 Views
Last Modified: 2013-12-03
To meet  the requirement for a project, I am using a windows service (made with VC6 using the old CComModule) that spawns a thread which simulates mouse events when certain conditions occur.

Now, this worked when the program was in Local Server mode and not doing any of the message handling/etc, but when I put it into Service mode and starte it, everything works right except for the mouse messages.  They don't seem to have any effect even though I receive no errors from the calls.

Any thoughts?
0
Comment
Question by:_corey_
  • 3
  • 2
5 Comments
 
LVL 19

Expert Comment

by:Dexstar
ID: 9735351
_corey_:

> Now, this worked when the program was in Local Server mode and not doing any
> of the message handling/etc, but when I put it into Service mode and starte
> it, everything works right except for the mouse messages.  They don't seem to
> have any effect even though I receive no errors from the calls.

What account is the service using?  In order to interact with the desktop, it is going to have to be the system service account, and you have to have the "interact with desktop" option checked in the services control panel.

If that doesn't work, then it might not be possible to have an application (directly) post messages to another user's windows.  There are ways around it though, so let me know if what I already suggested doesn't work.  :)

Hope that helps,
Dex*
0
 
LVL 8

Author Comment

by:_corey_
ID: 9735495
The "interact with desktop" option performs perfectly for my needs.

I just never tried to send such messages from a service before and was not sure where to look, so this really helped not waste any time :)

However, I was looking for a programming method instead of a property(which I should have), but it seems to require re-setting this option everytime you register the Service.  How can I have it defaulted, let's say after a registration of the service?
0
 
LVL 19

Accepted Solution

by:
Dexstar earned 500 total points
ID: 9735526
You'll have to dig through the ATL code, and find out where it calls "CreateService".  The 5th parameter is "dwServiceType".  If you set the SERVICE_INTERACTIVE_PROCESS flag in that parameter, then the service will always be created as interactive.

For more information on that API, check this site:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/createservice.asp

Hope That Helps,
Dex*
0
 
LVL 8

Author Comment

by:_corey_
ID: 9735557
Humble pie tastes good and speeds up productivity :) Thanks for the very quick help.  A few more points for the speed?
0
 
LVL 19

Expert Comment

by:Dexstar
ID: 9735600
_corey_:

> Humble pie tastes good and speeds up productivity :) Thanks for the very quick
> help.  A few more points for the speed?

If you wanted to, I certainly wouldn't object!  :)

Dex*
0

Featured Post

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question