Skip to content

Instantly share code, notes, and snippets.

@Aldaviva
Last active June 24, 2020 14:55
Show Gist options
  • Save Aldaviva/eca402167f11d60ca9019c3739e59bff to your computer and use it in GitHub Desktop.
Save Aldaviva/eca402167f11d60ca9019c3739e59bff to your computer and use it in GitHub Desktop.
Disable Windows 10 or Server ≥ 2016 from reopening programs on startup or reboot.

Usage

  1. Save the disable-program-reopen.ps1 file below to a directory on your computer, such as %SYSTEMROOT%\System32\GroupPolicy\User\Scripts\Logon.
  2. Allow unsigned local PowerShell scripts to run on your computer.
    1. Open PowerShell as an administrator.
    2. Run the following command and answer Y when it prompts you.
      Set-ExecutionPolicy RemoteSigned
  3. Set a Group Policy to run this script when users log on.
    1. Open the Local Group Policy Editor (gpedit.msc, or search for Group Policy in the Start Menu).
    2. Go to User Configuration → Windows Settings → Scripts (Logon/Logoff) → Logon.
    3. In the PowerShell Scripts tab, choose Add…
    4. Select the disable-program-reopen.ps1 file that you downloaded.

How It Works

  1. When Windows shuts down, it saves the user's running programs to the RunOnce registry key so they will reopen upon reboot.
  2. Each applicable program is added as a value to HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce with a name like Application Restart #0 and string data containing the absolute path of the executable file.
  3. This script runs before the RunOnce key is read, because Group Policy logon scripts run before Run and RunOnce.
  4. This script finds all values in the RunOnce key whose name start with Application Restart # and deletes them. It leaves all other values unchanged.
  5. Windows Explorer reads the RunOnce key and launches each of the programs.
  6. Since the RunOnce list already had all of the running programs from the previous Windows session deleted, Windows Explorer does not relaunch them.

Windows Versions

Microsoft added an official option to toggle this behavior. It seems to have been released with Windows 10 version 1803.

  1. Go to Settings → Accounts → Sign-in options.
  2. Under Privacy, disable "Use my sign-in info to automatically finish setting up my device and reopen my apps after an update or restart".

Unfortunately, many users report that the option is not present for them. Some editions of Windows don't include this option, including Windows 10 Enterprise, Windows Server 2016 (1607), and Windows Server 2019 (1809). For these operating systems, the group policy script below is still the way to go.

$runOnceKey = "HKCU:\Software\Microsoft\Windows\CurrentVersion\RunOnce"
Get-Item $runOnceKey | foreach Property | foreach {
if ($_ -like "Application Restart #*") {
Remove-ItemProperty -Path $runOnceKey -Name $_
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment