Solved

Using ::PostMessage and ::SendInput in a Service

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 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

11 Experts available now in Live!

Get 1:1 Help Now