How to auto-hide the taskbar from the command line
Asked Answered
J

3

13

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

Journalist answered 14/7, 2015 at 20:16 Comment(0)
N
14

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;
}
Nicolella answered 14/7, 2015 at 20:36 Comment(5)
This relies on undocumented behavior and doesn't work on multiple monitors. Use SHAppBarMessage.Subsidy
Why not ABM_SETSTATE ? #53367737Stacy
This is the only solution (of many, many) that worked for me. Thanks!Devine
This latter solution using SHAppBarMessage worked, but I needed to download and install Visual Studio 22 preview (40 GB O.o) to get the Developer Command Prompt for VS 2022, after which I couldn't figure out how to compile it. It sounds totally novice but the linking was the thing catching me, but eventually I sorted it out. Here's the command to use (can't do this in a regular cmd prompt, admin or otherwise), which must do done in the Developer Command prompt which is installed with VS 2022: cl autohidetaskbar.c shell32.libBromley
This is an excellent solution. It builds without error, doesn't require configuration, and is self-contained. Best of all, it doesn't require the user to restart Explorer, unlike any of the PowerShell solutions.Beast
A
31

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).

Affliction answered 9/11, 2017 at 12:35 Comment(9)
regedit.exe can also bump the value, note that $v[8] in the binary editor for regedit is column 1, row 2 (eight index AKA ninth entry), click the byte and type 03 or 02. Killing the explorer.exe process seems to be critical otherwise it will overwrite our regedit change normally.Zed
What an OUTSTANDING post with outstanding explanation, multiple OS vers addressed, critical discussion of undoing it, and the elucidation on the Explorer stoppage. This was the 15th and final webpage I studied for this, and even the top of this page had me 10 seconds from giving up. They left me helpless to nonmanually edit a registry substring, but you saved me(thanks,prev. commenter also). Moreover, each of "the 15" dealing with the idiotically arcane StuckRects3 approach proclaimed to do a mass overwrite of the entire [binary] string. That is simply destructive. Only you focused on byte 9.Stacy
I just did an attaboy but only in the comment section hoping it would survive, in case it's gone. (edit it: byte->position) Your powershell solution is rather perfect, but I wish it could preserve(i.e. restore)File Explorer windows that were open before invoking it (whether setting as 3 or as 2.) (I made two .BATs). I have noticed that In Task Man doing right click/restart SOMETIMES restores the folder windows, and sometimes loses them. The command here ("&Stop-Process -f -ProcessName explorer}") seem to always lose them. Not complaining at this awesome solution, but grasping for a nice tweak.Stacy
This should be the accepted as the correct answer, as it does not rely on external programs. Also you explained the reasoning behind it perfectly! The Windows 7 version also works on Windows 8.1 without problems.Claytor
This works perfectly. I am using Bootcamp on Mac and have been looking for a solution for literally hours. I just copied and pasted in the command and it just worked. I honestly had zero confidence that it would, but it works without fail. It even pops back up when you scroll at the bottom. +1 best answer ever.Bibb
Works perfectly!Pioneer
Works like a charm, @Journalist for other people who see this, this should be the correct solution.Sciential
This solution is very aggressive. It restarts the explorer process. This causes some pop-ins and -outs, reconnection of some stuff, and running some initialisation processes on each computer I’ve tried. Very aggressive, very aggressive.Devine
wanted to toggle the setting with my keyboard shortcut, here's a slightly modified command to toggle instead of turning on/off powershell -command "&{$p='HKCU:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\StuckRects3';$v=(Get-ItemProperty -Path $p).Settings;$v[8]=$v[8] -bxor 1;&Set-ItemProperty -Path $p -Name Settings -Value $v;&Stop-Process -f -ProcessName explorer}"Grindlay
N
14

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;
}
Nicolella answered 14/7, 2015 at 20:36 Comment(5)
This relies on undocumented behavior and doesn't work on multiple monitors. Use SHAppBarMessage.Subsidy
Why not ABM_SETSTATE ? #53367737Stacy
This is the only solution (of many, many) that worked for me. Thanks!Devine
This latter solution using SHAppBarMessage worked, but I needed to download and install Visual Studio 22 preview (40 GB O.o) to get the Developer Command Prompt for VS 2022, after which I couldn't figure out how to compile it. It sounds totally novice but the linking was the thing catching me, but eventually I sorted it out. Here's the command to use (can't do this in a regular cmd prompt, admin or otherwise), which must do done in the Developer Command prompt which is installed with VS 2022: cl autohidetaskbar.c shell32.libBromley
This is an excellent solution. It builds without error, doesn't require configuration, and is self-contained. Best of all, it doesn't require the user to restart Explorer, unlike any of the PowerShell solutions.Beast
S
2

Toggle autohide on/off

PowerShell solution:

$location = @{Path = 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\StuckRects3'; Name = 'Settings'}
$value = Get-ItemPropertyValue @location
$value[8] = if ($value[8] -Eq 122) {123} Else {122}
Set-ItemProperty @location $value
Stop-Process -Name Explorer

If using Windows 8 or older, replace Rects3 with Rects2. As with Grenade's solution, Explorer windows are closed.

Sheffie answered 14/5, 2023 at 10:3 Comment(1)
This works great. I'm working on a Kiosk like application that hides the taskbar and I needed something to toggle it.Diocese

© 2022 - 2024 — McMap. All rights reserved.