Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Using ::PostMessage and ::SendInput in a Service

Posted on 2003-11-12
5
Medium Priority
?
1,373 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_
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

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…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

670 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