Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have a program that needs to sit in the background and when a user connects to a RDP session it will do some environment setup 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 I have the terminal server launch this application. This is built as a windows forms application to keep the console window from showing up:

public static void Main()
{
    //(Snip...) Do some setup work

    Process proc = new Process();
    //(Snip...) Setup the process
    proc.Start();
    proc.WaitForExit();

    //(Snip...) 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?

like image 261
Scott Chamberlain Avatar asked May 07 '10 22:05

Scott Chamberlain


People also ask

How do I make programs not show up on taskbar?

Right-click on your taskbar > Taskbar settings. Under the Notification area, click "Select which icons appear on the taskbar" then disable the app you're looking for.

How do I make alt tab only show icons?

You can also press and hold the right Alt key, press and release the left Alt key, and press Tab to have Alt+Tab show open windows as classic icons instead of thumbnails.


1 Answers

You can create a hidden window that you use to handle the messages.

using System;
using System.Windows.Forms;

namespace WindowsApplication1
{
  class Program
  {
    [STAThread]
    static void Main(string[] args)
    {
      Application.Run(new MessageWindow());        
    }
  }

  class MessageWindow : Form
  {
    public MessageWindow()
    {
      this.ShowInTaskbar = false;
      this.WindowState = FormWindowState.Minimized;
      // added by MusiGenesis 5/7/10:
      this.FormBorderStyle = FormBorderStyle.FixedToolWindow;
    }

    protected override void WndProc(ref Message m)
    {
      base.WndProc(ref m);
    }
  }
}  
like image 172
Chris Taylor Avatar answered Oct 06 '22 03:10

Chris Taylor