A lightweight C++ utility for executing PowerShell scripts silently with error handling and process management.
- Unicode support for script paths
- Silent process execution (no window display)
- Exit code validation
- Comprehensive error logging
- Execution policy bypass capability
const std::wstring scriptPath = L"C:\\path\\to\\script.ps1";
if (RunPowerShellScript_Unicode(scriptPath)) {
// Script executed successfully
} else {
// Handle execution failure
}- Windows OS
- C++11 or later
- Visual Studio 2022 (or compatible MSVC compiler)
- Windows SDK
Compile with standard Windows API libraries:
cl /EHsc main.cpp
- Constructs a PowerShell command with execution policy bypass
- Creates a hidden process using CreateProcessW
- Waits for process completion
- Validates exit code
- Logs errors if applicable
scriptPath: Full path to the PowerShell script file (.ps1)
true: Script executed with exit code 0false: Execution failed or non-zero exit code