mirror of
https://github.com/ChrisTitusTech/winutil
synced 2026-02-04 15:00:09 +00:00
39 lines
1.2 KiB
PowerShell
39 lines
1.2 KiB
PowerShell
function Invoke-WinUtilExplorerUpdate {
|
|
<#
|
|
.SYNOPSIS
|
|
Refreshes the Windows Explorer
|
|
#>
|
|
param (
|
|
[string]$action = "refresh"
|
|
)
|
|
|
|
if ($action -eq "refresh") {
|
|
Invoke-WPFRunspace -DebugPreference $DebugPreference -ScriptBlock {
|
|
# Define the Win32 type only if it doesn't exist
|
|
if (-not ([System.Management.Automation.PSTypeName]'Win32').Type) {
|
|
Add-Type -TypeDefinition @"
|
|
using System;
|
|
using System.Runtime.InteropServices;
|
|
public class Win32 {
|
|
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
|
|
public static extern IntPtr SendMessageTimeout(
|
|
IntPtr hWnd, uint Msg, IntPtr wParam, string lParam,
|
|
uint fuFlags, uint uTimeout, out IntPtr lpdwResult);
|
|
}
|
|
"@
|
|
}
|
|
|
|
$HWND_BROADCAST = [IntPtr]0xffff
|
|
$WM_SETTINGCHANGE = 0x1A
|
|
$SMTO_ABORTIFHUNG = 0x2
|
|
|
|
[Win32]::SendMessageTimeout($HWND_BROADCAST, $WM_SETTINGCHANGE,
|
|
[IntPtr]::Zero, "ImmersiveColorSet", $SMTO_ABORTIFHUNG, 100,
|
|
[ref]([IntPtr]::Zero))
|
|
}
|
|
} elseif ($action -eq "restart") {
|
|
taskkill.exe /F /IM "explorer.exe"
|
|
Start-Process "explorer.exe"
|
|
}
|
|
}
|