How to make a program not show up in Alt-Tab or on the taskbar.

Posted by Scott Chamberlain on Stack Overflow See other posts from Stack Overflow or by Scott Chamberlain
Published on 2010-05-07T22:05:55Z Indexed on 2010/05/07 22:28 UTC
Read the original article Hit count: 197

Filed under:
|
|

I have a program that needs to sit in the background and when a user connects to a RDP session it will do some stuff then launch a program. when the program is closed it will do some housekeeping and logoff the session.

The current way I am doing it is like this I have the terminal server launch this application. I have it set as a windows forms application and my code is this

public static void Main()
{
    //Do some setup work
    Process proc = new Process();
    //setup the process
    proc.Start();
    proc.WaitForExit();
    //Do some housecleaning
    NativeMethods.ExitWindowsEx(0, 0);
}

I really like this because there is no item in the taskbar and there is nothing showing up in alt-tab. However to do this I gave up access to functions like void WndProc(ref Message m) So Now I can't listen to windows messages (Like WTS_REMOTE_DISCONNECT or WTS_SESSION_LOGOFF) and do not have a handle to use for for bool WTSRegisterSessionNotification(IntPtr hWnd, int dwFlags); I would like my code to be more robust so it will do the housecleaning if the user logs off or disconnects from the session before he closes the program.

Any reccomendations on how I can have my cake and eat it too?

© Stack Overflow or respective owner

Related posts about c#

Related posts about handle