use Win32::API; Win32::API->Import('wtsapi32.dll','WTSEnumerateSessions','NNNPP','N'); Win32::API->Import('wtsapi32.dll','WTSFreeMemory','P',''); while ( 1 ) { my $Count = pack 'L', 0; my $pSessionInfo = pack 'L', 0; WTSEnumerateSessions(0,0,1,$pSessionInfo,$Count); WTSFreeMemory($pSessionInfo); select undef, undef, undef, 0.01; }