Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Can I SendMessage() to another user's window within the same computer?

Can I SendMessage() to another user's window within the same computer?

Scheduled Pinned Locked Moved C / C++ / MFC
performancequestion
11 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Darrel Q Pham
    wrote on last edited by
    #1

    If so, where do I start looking? I understand I can use shared memory and other IPCs, but I want to know about SendMessage() specifically.

    S L 2 Replies Last reply
    0
    • D Darrel Q Pham

      If so, where do I start looking? I understand I can use shared memory and other IPCs, but I want to know about SendMessage() specifically.

      S Offline
      S Offline
      Saurabh Garg
      wrote on last edited by
      #2

      Don't you have msdn? SendMessage[^]. -Saurabh

      D 1 Reply Last reply
      0
      • S Saurabh Garg

        Don't you have msdn? SendMessage[^]. -Saurabh

        D Offline
        D Offline
        Darrel Q Pham
        wrote on last edited by
        #3

        I've searched and could not get an answer, and thats why I asked. It seems to me that there's no way to specify the user/session that I'm sending to with the current SendMessage function. I think I'm missing something though. Yes I am aware of "letmegooglethatforyou.com"

        S 1 Reply Last reply
        0
        • D Darrel Q Pham

          I've searched and could not get an answer, and thats why I asked. It seems to me that there's no way to specify the user/session that I'm sending to with the current SendMessage function. I think I'm missing something though. Yes I am aware of "letmegooglethatforyou.com"

          S Offline
          S Offline
          Saurabh Garg
          wrote on last edited by
          #4

          First of all no need to get cranky. I did not asked you to google for it, I mentioned MSDN. Everything you need to know about SendMessage is on the MSDN link I gave you. It is a simple function LRESULT SendMessage(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);. You pass the handle of the window you want to send message to, the message you want to sent and the parameters for that particular message.

          Darrel Q Pham wrote:

          It seems to me that there's no way to specify the user/session

          I don't think you understand how windows work. There are no sessions in windows, there are well windows. SendMessage is used to communicate between windows. For example, if I want to send left mouse button down to the desktop windows I will do this:

          SendMessage(GetDesktopWindow(), WM_LBUTTONDOWN, LPARAM MAKELPARAM(500, 500));

          This will send a left mouse button message to desktop windows at the (500, 500). -Saurabh

          D 1 Reply Last reply
          0
          • S Saurabh Garg

            First of all no need to get cranky. I did not asked you to google for it, I mentioned MSDN. Everything you need to know about SendMessage is on the MSDN link I gave you. It is a simple function LRESULT SendMessage(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);. You pass the handle of the window you want to send message to, the message you want to sent and the parameters for that particular message.

            Darrel Q Pham wrote:

            It seems to me that there's no way to specify the user/session

            I don't think you understand how windows work. There are no sessions in windows, there are well windows. SendMessage is used to communicate between windows. For example, if I want to send left mouse button down to the desktop windows I will do this:

            SendMessage(GetDesktopWindow(), WM_LBUTTONDOWN, LPARAM MAKELPARAM(500, 500));

            This will send a left mouse button message to desktop windows at the (500, 500). -Saurabh

            D Offline
            D Offline
            Darrel Q Pham
            wrote on last edited by
            #5

            Thank you, but that is not what I meant. I'm literally talking about another sending a message to a window on another user's login account. I have program A in Bob's login account communicating with program B in Alice's login account. Assume they are remote logging into the same computer. I use SendMessage() often in the same login, so I understand how it works in the local login. I did read somewhere that the HWND is like a global handle in the system, which means I could pass the HWND to another login and it'll make it valid, but I doubt that. I will verify this.

            S 1 Reply Last reply
            0
            • D Darrel Q Pham

              Thank you, but that is not what I meant. I'm literally talking about another sending a message to a window on another user's login account. I have program A in Bob's login account communicating with program B in Alice's login account. Assume they are remote logging into the same computer. I use SendMessage() often in the same login, so I understand how it works in the local login. I did read somewhere that the HWND is like a global handle in the system, which means I could pass the HWND to another login and it'll make it valid, but I doubt that. I will verify this.

              S Offline
              S Offline
              Saurabh Garg
              wrote on last edited by
              #6

              Okay, you did not mention this in you original post. First you have to find the handle to a window in other user's desktop. Then you can use that handle to send a message. To get the handle to a window in another users desktop you have to use EnumDesktops[^] to enumerate all the desktops in a workstation, find the one you need and then use EnumDesktopWindows[^] to enumerate the windows in that desktop. Hope this helps. -Saurabh

              D 1 Reply Last reply
              0
              • S Saurabh Garg

                Okay, you did not mention this in you original post. First you have to find the handle to a window in other user's desktop. Then you can use that handle to send a message. To get the handle to a window in another users desktop you have to use EnumDesktops[^] to enumerate all the desktops in a workstation, find the one you need and then use EnumDesktopWindows[^] to enumerate the windows in that desktop. Hope this helps. -Saurabh

                D Offline
                D Offline
                Darrel Q Pham
                wrote on last edited by
                #7

                Thank you, this is exactly what I'm looking for.

                1 Reply Last reply
                0
                • D Darrel Q Pham

                  If so, where do I start looking? I understand I can use shared memory and other IPCs, but I want to know about SendMessage() specifically.

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  Window Station and Desktop Functions[^] is a good place to start researching. Your probably going to run into the same security issues that you did in your CreateFileMapping project last week. Good Luck, -David Delaune

                  D 1 Reply Last reply
                  0
                  • L Lost User

                    Window Station and Desktop Functions[^] is a good place to start researching. Your probably going to run into the same security issues that you did in your CreateFileMapping project last week. Good Luck, -David Delaune

                    D Offline
                    D Offline
                    Darrel Q Pham
                    wrote on last edited by
                    #9

                    Thanks again. Another thing I forgot to mention is this will be for Server 2003, which allows multiple interactive station vs. XP which only allows one. I didnt mention this because I just found this out. I'm using XP right now, and this explains why I wrote my hwnd to a file(casting it as a dword) from program A in login/station A, and then open it with program B in login/station B, and failed when I attempt to use SendMessage with the hwnd that I read from the file. I will set up Server2003 to confirm this. From reading the links you guys gave me above, I think I can use OpenWindowStation() to open the login/station I want, use the hwinsta handle that the function returns, and use SetProcessWindowStation() to give my process access to that login/station. Then at this point I could use FindWindow() to find the window that I want to send the message to, and use SendMessage() to communicate with that window. When all is done, I can bring my process back to the previous login/station. This is unrelated, but if I said above is correct, does this mean I can launch my process in login/station A, set my process to belong to login/station B, create a thread in login/station B, spun an mfc dialog box inside that thread, set my process to belong to login/station A again, and it'll work correctly even if I have global variables that the dialog box accesses in my main process in the user A?

                    L 1 Reply Last reply
                    0
                    • D Darrel Q Pham

                      Thanks again. Another thing I forgot to mention is this will be for Server 2003, which allows multiple interactive station vs. XP which only allows one. I didnt mention this because I just found this out. I'm using XP right now, and this explains why I wrote my hwnd to a file(casting it as a dword) from program A in login/station A, and then open it with program B in login/station B, and failed when I attempt to use SendMessage with the hwnd that I read from the file. I will set up Server2003 to confirm this. From reading the links you guys gave me above, I think I can use OpenWindowStation() to open the login/station I want, use the hwinsta handle that the function returns, and use SetProcessWindowStation() to give my process access to that login/station. Then at this point I could use FindWindow() to find the window that I want to send the message to, and use SendMessage() to communicate with that window. When all is done, I can bring my process back to the previous login/station. This is unrelated, but if I said above is correct, does this mean I can launch my process in login/station A, set my process to belong to login/station B, create a thread in login/station B, spun an mfc dialog box inside that thread, set my process to belong to login/station A again, and it'll work correctly even if I have global variables that the dialog box accesses in my main process in the user A?

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #10

                      Hello Darrel, Beginning with Windows XP Service pack 2 and Windows Server 2003 Microsoft changed how you create processes with alternate credentials from the SYSTEM account. Prior to XP-SP2 it was a piece of cake. But with the new security technologies implemented its much more difficult. Microsoft has made a very weak attempt to document some of the changes for developers here: Windows XP Service Pack 2 - Security Information for Developers[^] But don't waste yout time looking at it, it pretty much doesn't contain anything useful. You may want to take a look at some source code instead. I found the folowing source code on the internet and thought you may want to take a look at some if its functions. alternate credentials from the SYSTEM account[^] Hope it helps, -David Delaune

                      D 1 Reply Last reply
                      0
                      • L Lost User

                        Hello Darrel, Beginning with Windows XP Service pack 2 and Windows Server 2003 Microsoft changed how you create processes with alternate credentials from the SYSTEM account. Prior to XP-SP2 it was a piece of cake. But with the new security technologies implemented its much more difficult. Microsoft has made a very weak attempt to document some of the changes for developers here: Windows XP Service Pack 2 - Security Information for Developers[^] But don't waste yout time looking at it, it pretty much doesn't contain anything useful. You may want to take a look at some source code instead. I found the folowing source code on the internet and thought you may want to take a look at some if its functions. alternate credentials from the SYSTEM account[^] Hope it helps, -David Delaune

                        D Offline
                        D Offline
                        Darrel Q Pham
                        wrote on last edited by
                        #11

                        Thank you. I have setup Server 2003 and created 2 user sessions, then tried using SendMessage() to communicate between two user sessions, which does not work. I've done much more searching and read that the hWnd global but is limited to the scope of the windows station. This makes sense in terms of security reasons, but sucks when I want more flexibility. I also came across a few messages that says hWnd is "system wide", which makes me confused again. I tested Named pipes and it works because it was designed to work across networks, so it will be the last resort. It would be nice to clear up the confusion though.

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups