----- makefile ----- # Nmake macros for building Windows 32-Bit apps !include all: display.exe display.obj: display.c $(cc) $(cflags) $(cvars) $(cdebug) display.c logonid.obj: logonid.c $(cc) $(cflags) $(cvars) $(cdebug) -Ic:\ddk\inc logonid.c display.exe: display.obj logonid.obj $(link) $(linkdebug) $(conflags) -out:display.exe display.obj logonid.obj $(conlibs) c:\ddk\lib\i386\free\ntdll.lib ----- display.c ----- #include #include extern ULONG GetWinCenterLogonId(HANDLE); char * GetWinCenterDisplay(char *display) { HANDLE shmem = 0; ULONG *shmemBase, ipaddr, dpy, screen; char string[25]; sprintf(string, "XDisplayAddress-%d", GetWinCenterLogonId(GetCurrentProcess())); if (!(shmem = OpenFileMapping(FILE_MAP_READ, FALSE, string)) || !(shmemBase = MapViewOfFile(shmem, FILE_MAP_READ, 0, 0, 0))) { if (shmem) CloseHandle(shmem); return NULL; } ipaddr = shmemBase[0]; dpy = shmemBase[1]; screen = shmemBase[2]; UnmapViewOfFile(shmemBase); CloseHandle(shmem); sprintf(display, "%d.%d.%d.%d:%d.%d", (ipaddr >> 24) & 0xff, (ipaddr >> 16) & 0xff, (ipaddr >> 8) & 0xff, ipaddr & 0xff, dpy, screen); return display; } int main(int argc, char **argv) { char display[50]; printf("%s\n", GetWinCenterDisplay(display) ? display : "Couldn't get display"); return 1; } ----- logonid.c ----- #include // // Citrix specific Process Information // NtQueryInformationProcess using ProcessCitrixInformation // typedef struct _PROCESS_CITRIX_INFORMATION { ULONG LogonId; } PROCESS_CITRIX_INFORMATION, *PPROCESS_CITRIX_INFORMATION; #define ProcessCitrixInformation 19 /* hopefully this won't change... */ ULONG GetWinCenterLogonId(HANDLE ProcessHandle) { PROCESS_CITRIX_INFORMATION ProcessInfo; NTSTATUS Status; Status = NtQueryInformationProcess(ProcessHandle, ProcessCitrixInformation, &ProcessInfo, sizeof(ProcessInfo), NULL); return NT_SUCCESS(Status) ? ProcessInfo.LogonId : 0; }