Programmatically detecting console (administrative) session on Windows Server 2008?
See the question and my original answer on StackOverflowIf you're looking for the id of the session that is currently attached to the physical console, the API is WTSGetActiveConsoleSessionId