You should probably check that you are running in session zero (at least if you are targeting Vista). You can use WTSRegisterSessionNotification, like in this sample:
[DllImport("kernel32.dll")]
private static extern int WTSGetActiveConsoleSessionId();