?
Solved

Using postmessage to post a message to another user?

Posted on 2002-06-02
11
Medium Priority
?
296 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
[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
11 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 1500 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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

752 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