0
votes

I have same user logged in into windows 7 station with several simultaneous sessions (like Concurrent RDP or log in at station and then via RDP).

UPDATE: Ok, my research in this question has been stuck at this point (python example to write less complicated code):

#!/usr/bin/env python
import ctypes
import ctypes.wintypes as wintypes
def enum_desktops():
    GetProcessWindowStation = user32.GetProcessWindowStation

    EnumDesktops = user32.EnumDesktopsW
    EnumDesktopsProc = ctypes.WINFUNCTYPE(wintypes.BOOL, wintypes.LPWSTR, wintypes.LPARAM)
    hwinsta = GetProcessWindowStation()

    def foreach_desktop(desk_name, lparam):
        print("Desktop %s"%desk_name)
        return True
    EnumDesktops(hwinsta, EnumDesktopsProc(foreach_desktop), desk_lparam)

This function prints information about "Default" and "Winlogon" dektops. If we try to enumerate window stations, we'll get only "WinSta0", while I can see potentially target process started on different logon session.

So, what should I use to find window for target Desktop?

daemon is not an option at this point at all.

2
If there's really no way or it's too complicated, I'll start daemon on every desktop to get control over windows. - Eir Nym
What do you mean simultaneous sessions? You mean of a specific applications or multiple same-user interactive sessions. - Austin T French
Concurrent RDP, like for server software - Eir Nym
I can't think of any great way to do this. You could implement logon scripts to write to a share for logons, and then clear it nightly / on logoff. Maybe scrape through events on the clients for open RDP sessions... Nothing real clean that I can think of, unless there is some terminal server or similar software that you could use instead of bare RDP. - Austin T French
What are you really trying to do by enumerating windows from a different desktop session? What are you trying to achieve by doing this. I ask because there may be a better way. - selbie

2 Answers

2
votes

Have a background app or task tray applet that gets launched with every desktop session. (Easily installed by adding an EXE path to the following registry key: HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\Current Version\Run).

The code that lives in that installed application will do two things:

  1. All the desktop windows enumeration and manipulation that you need to do that can only interact with the local desktop.

  2. Acts as a "Client" to your "server" app that runs on another desktop session. Your server app is what triggers the clients to do the window scanning. You can use almost any interprocess communication mechanism you want for this.

0
votes

Already some time passed from the time the question was posted, but in case someone needs it, I will post an answer.

What you have to do is set a desktop for your current thread, which is calling FindWindow. In this way, your calling thread will operate in other desktop and will find a window. For this to achieve, you have to use SetThreadDesktop WinAPI function.

For more info, check MSDN documentation on SetThreadDesktop.