#include
<stdio.h>#include <windows.h>#include <wtsapi32.h>#pragma comment(lib, "wtsapi32.lib")
void main()
{
DWORD ProcessId, SessionId;
BOOL Res=0;
DWORD winlogonPid = 0;
PWTS_PROCESS_INFO pProcessInfo=NULL;
DWORD ProcessCount = 0;
DWORD CurrentProcess = 0;
ProcessId = GetCurrentProcessId();
Res = ProcessIdToSessionId( ProcessId, &SessionId ); if (WTSEnumerateProcesses(WTS_CURRENT_SERVER_HANDLE, 0, 1, &pProcessInfo, &ProcessCount))
{ for (CurrentProcess = 0; CurrentProcess < ProcessCount; CurrentProcess++)
{
if( strcmp(pProcessInfo[CurrentProcess].pProcessName, "winlogon.exe") == 0 && pProcessInfo[CurrentProcess].SessionId == SessionId )
{
winlogonPid = pProcessInfo[CurrentProcess].ProcessId;
break;
}
}
WTSFreeMemory(pProcessInfo);
}else{
printf("WTSEnumerateProcesses() failed\n"); }
printf("Current winlogon's pid is %d\n",winlogonPid);
}