viewtopic.php?f=3&t=8805
Using platform invokation you can use Windows API functions in a little Powershell snippet. A lot of different API calls can be found in the internet to simulate the behavior of pressing F5 but none of them do all of the stuff that F5 invokes. Only one of the solutions that I found does direcly simulate F5 by sending the desired accelerator ID.
Code: Select all
@echo off &setlocal
set refresh_desktop=powershell.exe -NoProfile -ExecutionPolicy Bypass -Command ^"try{$c=Add-Type -Name WinAPI -PassThru -MemberDefinition '^
[DllImport(\"user32.dll\")] public static extern IntPtr GetShellWindow();^
[DllImport(\"user32.dll\")] public static extern int SendMessageW(IntPtr hWnd, uint Msg, UIntPtr wParam, IntPtr lParam);';^
$dsktp=$c::GetShellWindow(); $WM_COMMAND=273; $accel_F5=New-Object UIntPtr(41504); $nullptr=[IntPtr]::Zero;^
exit [int](($dsktp -eq $nullptr) -or ($c::SendMessageW($dsktp, $WM_COMMAND, $accel_F5, $nullptr) -ne 0));}catch{exit 1;}^"
:: Send command message 41504 to the Shell desktop window and call its window procedure. Number 41504 is the reverse-engineered accelerator
:: ID of the F5 virtual key in explorer windows. Thus, executing this macro simulates the same behavior as if you would have pressed F5 to
:: refresh the desktop. The advantage is that the desktop doesn't need to have the keyboard focus to make it work.
%refresh_desktop%
echo %errorlevel%
pause
I'd really like you to test the code on other versions and give feedback because I don't know if the accelerator ID ever changed.
Steffen