Hide Windows Taskbar using Salt

7 August 2015

What a ball ache! I could not find a way to hide the windows taskbar using a registry setting? I had to resort to executing a c# script using powershell.

Here are my Salt scripts:

hide_taskbar.ps1 is a powershell script with the contents shown below.

$AssemblyReferences = ( 
$Source = @"
using System;
using System.Drawing;
using System.Runtime.InteropServices;
public class HideTaskbar
    public static void Hide()
        TaskbarSettings taskbarSettings = new TaskbarSettings();
        taskbarSettings.cbSize = (UInt32)Marshal.SizeOf(taskbarSettings);
        taskbarSettings.hWnd = FindWindow("System_TrayWnd", null);
        taskbarSettings.lParam = 0x01;
        SHAppBarMessage(0x0a, ref taskbarSettings);

    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    public static extern IntPtr FindWindow(string strClassName, string strWindowName);
    public static extern UInt32 SHAppBarMessage(UInt32 dwMessage, ref TaskbarSettings pData);

    public struct TaskbarSettings
        public UInt32 cbSize;
        public IntPtr hWnd;
        public UInt32 uCallbackMessage;
        public UInt32 uEdge;
        public Rectangle rc;
        public Int32 lParam;
Add-Type -ReferencedAssemblies $AssemblyReferences  -TypeDefinition $Source

Below is my Salt init.sls script

    - name: 'C:\temp\hide_taskbar.ps1'
    - source: 'salt://hide_taskbar/hide_taskbar.ps1'

    - name: 'powershell -ExecutionPolicy ByPass -File C:\temp\hide_taskbar.ps1'
    - require:
      - file: hidetaskbar_script

    - name: 'C:\temp\hide_taskbar.ps1'
    - require:
      - cmd: hide_taskbar_ps_command

Hope this helps someone!