C# - Show&hide Windows Taskbar

  • 0 Replies
  • 151 Views

0 Members and 1 Guest are viewing this topic.

Offline Omega

    *
  • The Boss (Admin)
  • Black Hat Sec Member
  • Telegram: @BLACKHATSEC_FORUM
  • Posts: 190
  • Popularity: +1/-0
  • God of Malware
    • View Profile
    • Awards
« on: March 14, 2022, 09:22:59 AM »
C# - Show&hide Windows Taskbar

Code
//Win32 API needed
[DllImport("user32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern long SetWindowPos(long hWnd, long hWndInsertAfter, long X, long Y, long cx, long cy, long wFlags);

[DllImport("user32", EntryPoint = "FindWindowA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern long FindWindow(string lpClassName, string lpWindowName);

//constants needed
private const int SWP_HIDEWINDOW = 0x80;
private const int SWP_SHOWWINDOW = 0x40;

/// <summary>
/// method for handling the hiding & showing of the Windows Taskbar
/// </summary>
/// <param name="show">condition: are we hiding or showing</param>
/// <returns>true/false</returns>
public bool ShowHideWindowsTaskBar(bool show)
{
    try
    {
        //get the handle
        long hWnd = FindWindow("Shell_traywnd", "");

        //decide if we're hiding or showing the Taskbar
        switch (show)
        {
            case true:
                //show the Taskbar
                SetWindowPos(hWnd, 0, 0, 0, 0, 0, SWP_HIDEWINDOW);
                break;
            case false:
                //hide the Taskbar
                SetWindowPos(hWnd, 0, 0, 0, 0, 0, SWP_SHOWWINDOW);
                break;
        }
        return true;
    }
    catch (Win32Exception ex)
    {
        MessageBox.Show(ex.ToString());
        return false;
    }
   
}
  • Discord: BLACK HAT SEC#5222
  • [+]
  • [-]

  •