Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide taskbar using Python in Windows XP

Tags:

python

Is there a way to hide the Windows taskbar using Python? If not- is there a way to disable or to re-size and lock it using the registry?

like image 910
unice Avatar asked Jan 18 '23 08:01

unice


2 Answers

Microsoft support document KB186119 demonstrates how to hide the taskbar using Visual Basic. Here's a ctypes version for Python, but using ShowWindow instead of SetWindowPos:

import ctypes
from ctypes import wintypes

user32 = ctypes.WinDLL("user32")

SW_HIDE = 0
SW_SHOW = 5

user32.FindWindowW.restype = wintypes.HWND
user32.FindWindowW.argtypes = (
    wintypes.LPCWSTR, # lpClassName
    wintypes.LPCWSTR) # lpWindowName

user32.ShowWindow.argtypes = (
    wintypes.HWND, # hWnd
    ctypes.c_int)  # nCmdShow

def hide_taskbar():
    hWnd = user32.FindWindowW(u"Shell_traywnd", None)
    user32.ShowWindow(hWnd, SW_HIDE)

def unhide_taskbar():
    hWnd = user32.FindWindowW(u"Shell_traywnd", None)
    user32.ShowWindow(hWnd, SW_SHOW)
like image 68
Eryk Sun Avatar answered Jan 28 '23 02:01

Eryk Sun


Just to add to @eryksun answer, if you try this in windows 7 you would still get to see the start button... I did i little tweek in his code to

1) Hide the start button (with the hWnd_btn_start = user32.FindWindowW(u"Button", 'Start') )

2) Now you can pass Hide (default behaviour) or Show to the command line to show or hide the taskbar.

import ctypes
import sys

from ctypes import wintypes

user32 = ctypes.WinDLL("user32")

SW_HIDE = 0
SW_SHOW = 5

HIDE = True;

for idx,item in enumerate(sys.argv):
    print(idx, item);
    if (idx == 1 and item.upper() == 'SHOW'):
        HIDE = False;

#HIDE = sys.argv[1] = 'HIDE' ? True : False;


user32.FindWindowW.restype = wintypes.HWND
user32.FindWindowW.argtypes = (
    wintypes.LPCWSTR, # lpClassName
    wintypes.LPCWSTR) # lpWindowName

user32.ShowWindow.argtypes = (
    wintypes.HWND, # hWnd
    ctypes.c_int)  # nCmdShow

def hide_taskbar():
    hWnd = user32.FindWindowW(u"Shell_traywnd", None)
    user32.ShowWindow(hWnd, SW_HIDE)

    hWnd_btn_start = user32.FindWindowW(u"Button", 'Start')
    user32.ShowWindow(hWnd_btn_start, SW_HIDE)

def unhide_taskbar():
    hWnd = user32.FindWindowW(u"Shell_traywnd", None)
    user32.ShowWindow(hWnd, SW_SHOW)

if (HIDE):
    hide_taskbar();
else:
    unhide_taskbar();

Usage: To show the taskbar python hideTaskBar.py Show To hide the taskbar python hideTaskBar.py Hide

Again, many thanks to @eryksun

like image 32
Samuel Aiala Ferreira Avatar answered Jan 28 '23 01:01

Samuel Aiala Ferreira