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 = (
"System.Drawing"
)
$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);
//autohide
taskbarSettings.lParam = 0x01;
SHAppBarMessage(0x0a, ref taskbarSettings);
}
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr FindWindow(string strClassName, string strWindowName);
[DllImport("shell32.dll")]
public static extern UInt32 SHAppBarMessage(UInt32 dwMessage, ref TaskbarSettings pData);
[StructLayout(LayoutKind.Sequential)]
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
[HideTaskbar]::Hide()
Below is my Salt init.sls script
hidetaskbar_script:
file.managed:
- name: 'C:\temp\hide_taskbar.ps1'
- source: 'salt://hide_taskbar/hide_taskbar.ps1'
hide_taskbar_ps_command:
cmd.run:
- name: 'powershell -ExecutionPolicy ByPass -File C:\temp\hide_taskbar.ps1'
- require:
- file: hidetaskbar_script
delete_hidetaskbar_script:
file.absent:
- name: 'C:\temp\hide_taskbar.ps1'
- require:
- cmd: hide_taskbar_ps_command
Hope this helps someone!