Group Policy to Run Logon Script After Desktop Is Ready
If you configure your logon scripts in User Configuration » Policies » Windows Settings » Scripts, you might have noticed that they are launched at about the same time as explorer.exe
. That means sometimes the desktop is not fully ready when your script runs.
There is a policy Run logon scripts synchronously, which does the opposite of what the title of this article says: it defers the start of explorer.exe
until your logon scripts have finished running.
To make sure your script runs only after the desktop is ready, add it to User Configuration or Computer Configuration » Policies » Administrative Templates » System » Logon » Run these programs at logon.
This policy expects executable programs, so make sure to include powershell.exe
at the beginning. For example:
powershell.exe -ExecutionPolicy Unrestricted -WindowStyle Hidden -File script.ps1
Even with WindowStyle
set to Hidden
, the PowerShell window flashes briefly. To get rid of it completely, you can compile the script to an .exe
with PS2EXE, for example.