Solved

Using ::PostMessage and ::SendInput in a Service

Posted on 2003-11-12
5
1,331 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
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…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

896 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now