Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to auto-hide the taskbar from the command line

Does anyone know how I can automatically hide the task bar in windows 7 via command line or some other method?

like image 966
blakepeterman Avatar asked Jul 14 '15 20:07

blakepeterman


People also ask

Is there a command to hide taskbar?

Right-click the taskbar and select "Properties." If you're using Windows 8, select "Desktop" from the Start menu or press ⊞ Win + D first to open the desktop view. Check the "Auto-hide the taskbar" box. You'll find this in the "Taskbar" tab.

How do I make my taskbar always hide?

Step 1: Right-click on an empty spot on the taskbar, click Taskbar settings option to open Taskbar settings page of the Settings app. Step 2: Here, turn on Automatically hide the taskbar in desktop mode option to hide the Taskbar immediately.


2 Answers

Here's a little C program that will toggle the hidden/shown state of the taskbar window. Note that when it's hidden it's actually gone from the screen completely (it's not in auto-hide mode).

#include <windows.h>

int main() {
    HWND hwnd = FindWindow("Shell_traywnd", "");
    if (IsWindowVisible(hwnd))
        SetWindowPos(hwnd,0,0,0,0,0,SWP_HIDEWINDOW);
    else
        SetWindowPos(hwnd,0,0,0,0,0,SWP_SHOWWINDOW);
    return 0;
}

Using SHAppBarMessage. This one toggles the autohide state.

#include <windows.h>
#include <shellapi.h>

// This isn't defined for me for some reason.
#ifndef ABM_SETSTATE
#define ABM_SETSTATE 0x0000000A
#endif

int main() {
    APPBARDATA abd = {sizeof abd};
    UINT uState = (UINT) SHAppBarMessage(ABM_GETSTATE, &abd);
    LPARAM param = uState & ABS_ALWAYSONTOP;
    if (uState & ABS_AUTOHIDE)
        abd.lParam = param;
    else
        abd.lParam = ABS_AUTOHIDE | param;
    SHAppBarMessage(ABM_SETSTATE, &abd);
    return 0;
}
like image 39
ooga Avatar answered Sep 22 '22 09:09

ooga


To autohide the taskbar from a cmd prompt or in a .cmd or. bat file:

Windows 7 (StuckRects2)

powershell -command "&{$p='HKCU:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\StuckRects2';$v=(Get-ItemProperty -Path $p).Settings;$v[8]=3;&Set-ItemProperty -Path $p -Name Settings -Value $v;&Stop-Process -f -ProcessName explorer}"

Windows 10 (StuckRects3)

powershell -command "&{$p='HKCU:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\StuckRects3';$v=(Get-ItemProperty -Path $p).Settings;$v[8]=3;&Set-ItemProperty -Path $p -Name Settings -Value $v;&Stop-Process -f -ProcessName explorer}"

Explanation

The registry key which stores this value also stores a number of other settings. Since we only want to change position 9 ($v[8] in the cmd) of that registry setting, we need to preserve the other settings.

Normally from cmd, it's enough to use a reg add command to modify the registry, but we use powershell because it makes it easy to preserve the other settings stored under the same registry key.

Explorer also needs to be restarted to pick up the change. We use Stop-Process because Windows automatically restarts Explorer when it is stopped.

Note: change $v[8]=3 to $v[8]=2 in the commands above to undo this change (if you want the taskbar to be always visible).

like image 164
grenade Avatar answered Sep 20 '22 09:09

grenade