Solved

Using postmessage to post a message to another user?

Posted on 2002-06-02
11
289 Views
Last Modified: 2013-12-04
Hi all,

I have the following problem:  Inside a service I want to post a registered windows message to all desktop windows.  Now, that is no problem, everything works.  But only if the service starts up as the system user.  When I want to send a message to user A (that is logged in) with the service that is started as user B.  Then the message is send but not received by the application of user A.

I was wondering if anybody can help me, I have used BroadcastMessage and Postmessage, but I don't find any correct parameter I can pass.

Thanx in advance
0
Comment
Question by:meirchen
11 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 7050147
You will have to impersonate the user's context first. e.g like

E.g.:

  HANDLE          hToken  =   NULL;

  if  (   !LogonUser  (   ( char*) pszUsername,
                          NULL,
                          ( char*) pszPwd,
                          LOGON32_LOGON_INTERACTIVE,
                          LOGON32_PROVIDER_DEFAULT,
                          &hToken
                      )
      )
      {
          return  (   GetLastError    ());
      }

  if  (   !ImpersonateLoggedOnUser    (   hToken)
      )
      {
          return  (   GetLastError    ());
      }

You could obtain a token from a process the user is running (explorer.exe is a good choice <s>). You'll nedd the PID to call 'OpenProcess()', then 'OpenProcessToken()' with 'TOKEN_IMPERSONATE' access. See http://support.microsoft.com/default.aspx?scid=kb;EN-US;q175030 ("HOWTO: Enumerate Applications Using Win32 APIs (Q175030)") on how to get that PID - it comes with sample code.
0
 
LVL 32

Expert Comment

by:jhance
ID: 7050788
0
 

Author Comment

by:meirchen
ID: 7051768
Sorry about the open questions, I have totally forgotten about them, Won't do it again. sorry
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 86

Expert Comment

by:jkr
ID: 7054680
>>Won't do it again. sorry

Are you sort of forgetting about this one?
0
 
LVL 1

Expert Comment

by:Toad224
ID: 7054878
The best way to do what you're talking about would probably be to use DDE.  Also, if you're looking to broadcast, you can broadcast with postmessage by specifying the hwnd as -1.  Hope this helps.

Good luck!
0
 
LVL 86

Expert Comment

by:jkr
ID: 7055182
>>The best way to do what you're talking about would probably be to use DDE

DDE from a service seems even more complicated to me....

BTW, as the main reason for not being able to send messages to user windows is that you simply do not have access to the desktop, allowing the service to "interact with the desktop" (can be done from the control panel applet or by setting "SERVICE_INTERACTIVE_PROCESS" when calling "CreateService()") might already help...
0
 

Author Comment

by:meirchen
ID: 7057387
Thanx for the information

I have tried the solution of jkr, but for the moment I don't find the correct way, I have succeeded in logging on with another username in my program (as interactive) but I haven't received any messages on my desktop programs.  I still have to try it with other parameters and so, and I hope to have a possible solution tomorrow.

I don't know DDE, but I will look in to it.

Starting the service as System user is not possible, since the service needs to connect to other computers on the network.  And If I use '\\ComputerName\Sharename' he doesn't find the path.  I think it is because the system user is user only for the local PC, and not for a network.

If anyone has another idea, I'll be happy to receive it.
0
 
LVL 86

Expert Comment

by:jkr
ID: 7057414
Try the method I described in my first post - it sure is more compilcated, but also more reliable.
0
 
LVL 86

Expert Comment

by:jkr
ID: 10668287
The Q is answered
0
 
LVL 86

Expert Comment

by:jkr
ID: 10669898
Thank you for responding! :o)
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Enable Clear Text in Win 8.1 7 47
Windows Drag & Drop Location 2 112
reboot server with scheduled time and week base 4 61
Shared files and folders migration 2 27
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
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…
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…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

756 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