Solved

Using postmessage to post a message to another user?

Posted on 2002-06-02
11
285 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
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.

 
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

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

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…
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…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

919 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

17 Experts available now in Live!

Get 1:1 Help Now