Windows Setup Scripts

Posted on  by admin

%WINDIR%\Setup\Scripts\SetupComplete.cmd: This script runs with local system permissions and starts immediately after the user sees the desktop. This setting is disabled when using OEM product keys, except on Enterprise editions and Windows Server operating systems. %WINDIR%\Setup\Scripts\ErrorHandler.cmd: This script runs automatically when Setup encounters a fatal error.

It runs with local system permission. After Windows is installed but before the logon screen appears, Windows Setup searches for the SetupComplete.cmd file in the %WINDIR%\Setup\Scripts\ directory. If a SetupComplete.cmd file is found, Windows Setup runs the script. Windows Setup logs the action in the C:\Windows\Panther\UnattendGC\Setupact.log file. Setup does not verify any exit codes or error levels in the script after it executes SetupComplete.cmd.

You can't reboot the system and resume running SetupComplete.cmd. You should not reboot the system by adding a command such as shutdown -r. This will put the system in a bad state. If the computer joins a domain during installation, the Group Policy that is defined in the domain is not applied to the computer until Setupcomplete.cmd is finished.

  • This is to make sure that the Group Policy configuration activity does not interfere with the script.
  • If the script is not found, a dialog box is displayed with the error text.
  • A user must dismiss the dialog box before Windows Setup exits.
  • If the script is found, the script executes synchronously.
  • No dialog box or error text is displayed.
  • After the ErrorHandler.cmd script has finished running, Windows Setup exits.
  • Mount the image, and add it to the image, in %WINDIR%\Setup\Scripts\ErrorHandler.cmd. Unmount the image. Add ErrorHandler.cmd to a temporary file location (for example, C:\Temp\ErrorHandler.cmd), and then run Windows Setup using the /m option.
  • This can be especially useful to set up language-specific apps or content after the user has already selected their language.
  • Use these scripts sparingly because long scripts can prevent the user from reaching the Start screen quickly.
  • For retail versions of Windows, additional restrictions apply to these scripts.
  • For info, see the Licensing and Policy guidance on the OEM Partner Center. When you add a script using FirstLogonCommands, it will be triggered on the next boot, even if you boot into audit mode using Ctrl+Shift+F3.
  • Create tasks in the Task Scheduler to clear
    • %SystemRoot%\SoftwareDistribution\Download
    • %TEMP%
  • Unpin all Start menu tiles;
  • Pin shortcuts to Start menu using syspin.exe
    • Three shortcuts are preconfigured to be pinned: Control Panel, "old style" Devices and Printers, and Command Prompt
  • Turn on Controlled folder access and add protected folders using dialog menu;
  • Add exclusion folder from Microsoft Defender Antivirus scanning using dialog menu;
  • Add exclusion file from Microsoft Defender Antivirus scanning using dialog menu;
  • Refresh desktop icons, environment variables and taskbar without restarting File Explorer;
  • Many more File Explorer and context menu "deep" tweaks.

For example, the script for version 2004 is 3488 lines, and the developer recommends that users configure the whole script to their own preference.

Advanced users will likely have no issues modifying the script, but for others who aren't familiar with PowerShell, the script contains comments and documentation to help you on your way.

In order to run it on the system, it requires that you set the execution policy to Bypass, as Windows 10 will refuse to run the script otherwise.

To run it:

  • Open an elevated PowerShell prompt with Windows+X and selecting the option (if you changed this to Command Prompt, search for PowerShell in the Start menu and open as Administrator instead.
  • Run the command: Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process -Force
  • Run the PowerShell script or Start.cmd as administrator afterwards

Depending on how you edited the script, the program will show you a form-based set of options for removing programs or other options.

All in all, you should only try this on new installs, and if you decide to do it on your system without reinstalling, run a backup first so you can roll back. It goes without saying that this requires a bit of patience and is probably not for the average user, but more the power user.

In any case, if you are able to set up the script to how you like, you should be able to easily tweak newer versions of it for later versions of Windows. Dmitry is also offering some user support and listening to feedback by maintaining a few topics on various communities such as Reddit, and the feedback from users appears to be positive with over 32k downloads so far. You can find those links at the bottom of the Windows 10 Setup Script GitHub page.

Let us know in the comments if you give it a whirl yourself and what you think of it.