Solved

Using postmessage to post a message to another user?

Posted on 2002-06-02
11
284 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
 
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

758 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

22 Experts available now in Live!

Get 1:1 Help Now