Skip to content

0x0BSoD/WUpdaterCMD

Repository files navigation

WUpdaterCMD

A modern C++ command-line tool for automating Windows Update operations. This tool is designed for system administrators and automation scenarios where you need to programmatically search, download, and install Windows updates.

Features

  • πŸ” Search for updates using customizable criteria
  • ⬇️ Download updates automatically or interactively
  • πŸ“¦ Install updates with progress reporting
  • πŸ€– Quiet mode for automation scenarios
  • πŸ’» Modern C++17 codebase with smart pointers and proper memory management
  • πŸ› οΈ CMake build system for flexible compilation

Requirements

  • Windows OS: Windows 10, Windows 11, Windows Server 2016+
  • Compiler:
    • Visual Studio 2019 or newer (recommended)
    • MinGW-w64 with GCC 7.0+ (experimental)
  • CMake: Version 3.15 or higher
  • Administrator privileges: Required for installing updates

Building the Project

Using the Build Script (Easiest)

Simply run the provided batch file:

# Release build (default)
build.bat

# Debug build
build.bat Debug

Manual CMake Build

# Create build directory
mkdir build
cd build

# Configure CMake
cmake .. -DCMAKE_BUILD_TYPE=Release

# Build
cmake --build . --config Release

Visual Studio

# Generate Visual Studio solution
mkdir build
cd build
cmake .. -G "Visual Studio 16 2019"

# Open the generated .sln file or build from command line
cmake --build . --config Release

Usage

WUpdaterCMD.exe -c <criteria_file> [options]

Options

Option Description
-h, --help Show help message
-c, --criteria PATH Specify the path to file with search criteria (required)
-q, --quiet Run without asking for confirmation (for automation)

Examples

Interactive mode with criteria file:

WUpdaterCMD.exe -c criteria.txt

Automated mode (no prompts):

WUpdaterCMD.exe -c criteria.txt --quiet

Search Criteria

Create a text file with Windows Update search criteria. The criteria uses the Windows Update Agent API query syntax.

Example criteria.txt

IsInstalled=0 and Type='Software' and IsHidden=0

Common Criteria Patterns

All uninstalled software updates:

IsInstalled=0 and Type='Software'

Security updates only:

IsInstalled=0 and Type='Software' and CategoryIDs contains '0FA1201D-4330-4FA8-8AE9-B877473B6441'

Critical and security updates:

IsInstalled=0 and Type='Software' and (CategoryIDs contains '0FA1201D-4330-4FA8-8AE9-B877473B6441' or CategoryIDs contains 'E6CF1350-C01B-414D-A61F-263D14D133B4')

Updates not hidden:

IsInstalled=0 and IsHidden=0

For more information on search criteria, see the Microsoft documentation.

Modernization Changes (2024)

This project has been modernized from the original 2019 version with the following improvements:

Code Quality

  • βœ… Updated to C++17 standard
  • βœ… Replaced raw pointers with COM smart pointers (_com_ptr_t)
  • βœ… Proper exception handling with try-catch blocks
  • βœ… RAII principles for resource management
  • βœ… Better error messages and logging
  • βœ… Organized code with namespaces (WUpdater)
  • βœ… Strong typing with enums instead of magic numbers

Build System

  • βœ… Added CMake support for flexible building
  • βœ… Cross-compiler support (MSVC, MinGW)
  • βœ… Automated build scripts
  • βœ… Proper dependency management

Project Structure

  • βœ… Added .gitignore for clean repository
  • βœ… MIT License included
  • βœ… Improved documentation
  • βœ… Example configuration files

Memory Management

  • βœ… No memory leaks with smart pointers
  • βœ… Automatic cleanup with RAII
  • βœ… Proper COM reference counting

Project Structure

WUpdaterCMD/
β”œβ”€β”€ main.cpp          # Main implementation
β”œβ”€β”€ main.h            # Header file with declarations
β”œβ”€β”€ CMakeLists.txt    # CMake build configuration
β”œβ”€β”€ build.bat         # Windows build script
β”œβ”€β”€ criteria.txt      # Example search criteria
β”œβ”€β”€ README.md         # This file
β”œβ”€β”€ LICENSE           # MIT License
└── .gitignore        # Git ignore rules

How It Works

  1. Initialization: The tool initializes COM and creates a Windows Update session
  2. Search: Searches for updates matching the criteria from your criteria file
  3. Display: Lists all found updates with release dates and download status
  4. Download: Downloads updates that aren't already cached (with optional confirmation)
  5. Install: Installs the downloaded updates (with optional confirmation)
  6. Report: Provides detailed results for each operation

Troubleshooting

Build Issues

Error: CMake not found

Error: Cannot find wuapi.h

  • Ensure you have Windows SDK installed
  • Install Visual Studio with "Desktop development with C++" workload

Runtime Issues

Error: Access Denied

  • Run the program as Administrator
  • Windows Update operations require elevated privileges

Error: No updates found

  • Check your search criteria syntax
  • Ensure Windows Update service is running: net start wuauserv
  • Verify network connectivity

Error: COM initialization failed

  • Ensure no other update operations are running
  • Restart Windows Update service

Contributing

Contributions are welcome! Please feel free to submit pull requests or open issues for bugs and feature requests.

License

This project is licensed under the MIT License - see the LICENSE file for details.

History

  • 2024: Modernized with C++17, CMake, smart pointers, and improved error handling
  • 2019: Original weekend project, built with Visual Studio 2019

Acknowledgments

  • Uses Windows Update Agent (WUA) API
  • Built with modern C++ practices and COM smart pointers

See Also


Note: This tool is intended for system administrators and advanced users. Always test in a non-production environment first and ensure you have proper backups before installing updates.

About

Small CMD tool to get and install updates. Suitable for other automation.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors