Are you tired of manually installing and updating your favorite applications every time you reinstall Windows 11? Learning how to automate this process can save you countless hours! In this guide, we’ll walk you through creating a winget script that simplifies the installation and updating of applications using Microsoft’s Windows Package Manager.

With the increasing reliance on apps for productivity, having a robust method to manage them becomes essential. By implementing a custom batch script, you’ll ensure that your essential applications are always up-to-date and ready to use every time you set up your Windows environment.

Creating a Winget Script for Windows 11

Follow these easy-to-understand steps to create a script that automatically installs and updates your applications using winget.

1. Compile a List of Desired Applications

Your first task is to create a comprehensive list of application IDs for the programs you wish to install. Here’s how you can achieve that:

  1. Open the Start menu.
  2. Search for Command Prompt (or Windows Terminal), right-click on the top result, and select Run as administrator.
  3. Input the command below to find the application identification number:
  4. winget search APP-NAME

  5. Ensure you use a unique keyword for your APP-NAME. For apps with spaces in their names, remember to enclose them in quotation marks.

    For example, searching for VLC would involve typing:

    winget search "VLC"

    Repeat for each application, recording its ID for later use in your script.

2. Craft the Winget Batch Script

Now it’s time to create the actual script that will perform the installations. Here’s how you can set it up:

  1. Open the Start menu.
  2. Launch Notepad or another text editor of your choice.
  3. Paste the following code into the text file:
  4. @echo offsetlocal enabledelayedexpansion

    :: List of application IDsset apps=Microsoft. WindowsTerminal. Preview Microsoft. Edge. Dev Microsoft. PowerToys

    for %%A in (%apps%) do ( echo Processing %%A…winget list –id %%A > temp_check.txt 2>&1 findstr /C:”No installed package found”temp_check.txt >nul if! errorlevel! equ 0 ( echo %%A not installed. Installing…winget install –id %%A –silent –accept-source-agreements –accept-package-agreements ) else ( echo %%A is installed. Attempting upgrade…winget upgrade –id %%A –silent –accept-source-agreements –accept-package-agreements if! errorlevel! neq 0 ( echo Upgrade failed for %%A or no update available.) ) echo.)del temp_check.txt >nul 2>&1endlocal

  5. In the section marked set apps=, list the application IDs you wish to manage, separating each ID with a space.
  6. Tip: Replace the example IDs with the ones specific to your applications.
  7. Click on File and choose Save As.
  8. Choose a location to save your file, name it as you like, and remember to use the .bat file extension.
  9. Click Save.

Understanding the Batch Script Components

  • @echo off – Suppresses command echoing for cleaner output.
  • setlocal enabledelayedexpansion – Enables real-time variable access within loops.
  • set apps= – Sets the list of applications to process.
  • for %%A in (%apps%) do () – Iterates over each app ID to check installation status.
  • winget list – Checks if each app is installed by writing output to a temporary file.
  • findstr – Searches for “No installed package found”to determine if installation is necessary.
  • winget install or winget upgrade – Executes installation or upgrade commands based on the app status.
  • del temp_check.txt – Cleans up temporary files post-execution.
  • endlocal – Restores the environment after script execution.

3. Set the Script to Run Automatically

Select one of the following methods to execute your batch script smoothly on Windows 11:

A. Manual Execution

  1. Right-click your .bat file and select Run as administrator.

This method is perfect for initial testing but will require you to manually start the script each time thereafter.

B. Adding to Startup

  1. Access the Run dialog via the Start menu.
  2. Type shell:startup and press Enter to navigate to the Startup folder.
  3. Place a shortcut to your .bat file in this folder.

With this setup, the script will run automatically each time you log in, keeping your apps updated without any additional effort. However, note that elevation prompts will still appear as needed for installations.

C. Schedule a Task

  1. Search for Task Scheduler in the Start menu and open it.
  2. (Optional) Create a new folder by right-clicking on the “Task Scheduler Library”and naming it (e.g., My Tasks).
  3. In your desired folder, right-click and select Create Task.
  4. Fill in the Name field with a descriptive title (e.g., My Apps).
  5. Select Run whether the user is logged on or not and check the option for Run with highest privileges.
  6. Navigate to the Triggers tab and click the New button.
  7. Choose a trigger (like At logon or At startup).
  8. Set other conditions as necessary and click OK.
  9. In the Actions tab, click New and choose Start a program.
  10. Under “Program/script, ”type:
  11. cmd.exe

  12. In the “Add arguments”box, enter:
  13. /c "C:\path\to\YOUR-SCRIPT.bat"

  14. Proceed to click OK and ensure that power conditions are set to allow task execution.

With this scheduled method, your applications will install and update automatically per your specified triggers without user intervention, making for an efficient setup!

Frequently Asked Questions

1. Can I use winget to install apps not in the official repository?

No, winget primarily works with applications that are available in the Windows Package Manager repository. However, you can manually install apps outside this repository after your main installations are complete.

2. What should I do if winget fails to install an application?

If winget fails to install an application, double-check the application ID in your script. Ensure the app is available in the winget repository and that your internet connection is stable. Also, try running the script with administrative privileges if you haven’t already.

3. How can I update the list of applications in my script?

To update the application list in your script, simply edit the line with set apps= in your batch file and add or remove app IDs as necessary. Save the changes and run the script again for the new configurations to take effect.

Source & Images

Leave a Reply

Your email address will not be published. Required fields are marked *