Skip to content

Commit

Permalink
create ep refresh function & map tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
MyDrift-user committed Aug 24, 2024
1 parent bcfbce6 commit 2fcf076
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 15 deletions.
12 changes: 3 additions & 9 deletions config/tweaks.json
Original file line number Diff line number Diff line change
Expand Up @@ -2743,9 +2743,7 @@
Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"Personal\" -Value \"$env:userprofile\\Documents\" -Type ExpandString
Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"{F42EE2D3-909F-4907-8871-4C22FC0BF756}\" -Value \"$env:userprofile\\Documents\" -Type ExpandString
Set-ItemProperty -Path \"HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\" -Name \"{0DDD015D-B06C-45D5-8C4C-F59713854639}\" -Value \"$env:userprofile\\Pictures\" -Type ExpandString
Write-Host \"Restarting explorer\"
taskkill.exe /F /IM \"explorer.exe\"
Start-Process \"explorer.exe\"
Invoke-WinUtilExplorerRefresh

Write-Host \"Waiting for explorer to complete loading\"
Write-Host \"Please Note - The OneDrive folder at $OneDrivePath may still have items in it. You must manually delete it, but all the files should already be copied to the base user folder.\"
Expand Down Expand Up @@ -3054,18 +3052,14 @@
"InvokeScript": [
"
New-Item -Path \"HKCU:\\Software\\Classes\\CLSID\\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\" -Name \"InprocServer32\" -force -value \"\"
Write-Host Restarting explorer.exe ...
$process = Get-Process -Name \"explorer\"
Stop-Process -InputObject $process
Invoke-WinUtilExplorerRefresh
"
],
"UndoScript": [
"
Remove-Item -Path \"HKCU:\\Software\\Classes\\CLSID\\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\" -Recurse -Confirm:$false -Force
# Restarting Explorer in the Undo Script might not be necessary, as the Registry change without restarting Explorer does work, but just to make sure.
Write-Host Restarting explorer.exe ...
$process = Get-Process -Name \"explorer\"
Stop-Process -InputObject $process
Invoke-WinUtilExplorerRefresh
"
],
"link": "https://christitustech.github.io/winutil/dev/tweaks/z--Advanced-Tweaks---CAUTION/RightClickMenu"
Expand Down
33 changes: 33 additions & 0 deletions functions/private/Invoke-WinUtilExplorerRefresh.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
function Invoke-WinUtilExplorerRefresh {
<#
.SYNOPSIS
Refreshes the Windows Explorer
#>

Invoke-WPFRunspace -DebugPreference $DebugPreference -ScriptBlock {
# Send the WM_SETTINGCHANGE message to all windows
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
$timeout = 100

# Send the broadcast message to all windows
[Win32]::SendMessageTimeout($HWND_BROADCAST, $WM_SETTINGCHANGE, [IntPtr]::Zero, "ImmersiveColorSet", $SMTO_ABORTIFHUNG, $timeout, [ref]([IntPtr]::Zero))
}
}
3 changes: 0 additions & 3 deletions functions/private/Invoke-WinUtilSnapFlyout.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ function Invoke-WinUtilSnapFlyout {
Write-Host "Disabling Snap Assist Flyout On startup"
$value = 0
}
# taskkill.exe /F /IM "explorer.exe"
$Path = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced"
taskkill.exe /F /IM "explorer.exe"
Set-ItemProperty -Path $Path -Name EnableSnapAssistFlyout -Value $value
Start-Process "explorer.exe"
} catch [System.Security.SecurityException] {
Write-Warning "Unable to set $Path\$Name to $Value due to a Security Exception"
} catch [System.Management.Automation.ItemNotFoundException] {
Expand Down
3 changes: 0 additions & 3 deletions functions/private/Invoke-WinUtilSnapSuggestion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ function Invoke-WinUtilSnapSuggestion {
Write-Host "Disabling Snap Assist Suggestion On startup"
$value = 0
}
# taskkill.exe /F /IM "explorer.exe"
$Path = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced"
taskkill.exe /F /IM "explorer.exe"
Set-ItemProperty -Path $Path -Name SnapAssist -Value $value
Start-Process "explorer.exe"
} catch [System.Security.SecurityException] {
Write-Warning "Unable to set $Path\$Name to $Value due to a Security Exception"
} catch [System.Management.Automation.ItemNotFoundException] {
Expand Down
2 changes: 2 additions & 0 deletions functions/public/Invoke-WPFToggle.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ function Invoke-WPFToggle {
"WPFToggleTaskbarAlignment" {Invoke-WinUtilTaskbarAlignment $(Get-WinUtilToggleStatus WPFToggleTaskbarAlignment)}
"WPFToggleDetailedBSoD" {Invoke-WinUtilDetailedBSoD $(Get-WinUtilToggleStatus WPFToggleDetailedBSoD)}
}

Invoke-WinUtilExplorerRefresh
}

0 comments on commit 2fcf076

Please sign in to comment.