Command Library
CMD, PowerShell, and async command-execution nodes for trusted Windows workflows.
Use this library for trusted command execution, diagnostics, setup tools, and launcher workflows.
Include The Module
Command Output
Hidden mode works for normal non-admin commands. Elevated commands use Windows UAC and cannot use the same silent output-capture path.
#include "HardwareInfoLibrary.h"PublicDependencyModuleNames.AddRange(
new string[]
{
"Core",
"CoreUObject",
"Engine",
"DeviceFrameworkModule"
}
);Run Command Prompt Command
Runs a cmd.exe command immediately.
This synchronous node is formally deprecated in favor of the unified async flow provided by Execute CLI Commands.
| Pin | Direction | Purpose |
|---|---|---|
Command | Input | Full command text passed to cmd.exe /S /C. |
bRunAsAdmin | Input | Requests elevation through UAC. |
bHidden | Input | Hides the command window when Windows allows it. |
Return Value | Output | True when the process started successfully. |
#include "HardwareInfoLibrary.h"
void AMySystemHelper::RunPromptCommand()
{
const bool bStarted = USystemInfoBPLibrary::ExecuteWindowsCMD(TEXT("echo Hello from CMD"), false, true);
if (bStarted)
{
UE_LOG(LogTemp, Log, TEXT("Command prompt started."));
}
}Run PowerShell Command
Runs a powershell.exe command immediately.
This synchronous node is formally deprecated in favor of the unified async flow provided by Execute CLI Commands.
| Pin | Direction | Purpose |
|---|---|---|
Command | Input | Full PowerShell command text. |
bRunAsAdmin | Input | Requests elevation through UAC. |
bHidden | Input | Hides the PowerShell window when Windows allows it. |
Return Value | Output | True when the process started successfully. |
#include "HardwareInfoLibrary.h"
void AMySystemHelper::RunPowerShellCommand()
{
const bool bStarted = USystemInfoBPLibrary::ExecutePowerShell(TEXT("Get-Date"), false, true);
if (bStarted)
{
UE_LOG(LogTemp, Log, TEXT("PowerShell command started."));
}
}Execute CLI Commands
Runs CMD or PowerShell asynchronously without blocking the game thread. Features thread-safe isolated data pipes to prevent memory contamination during concurrent execution.
Timeout Warning
If the command times out, a timeout warning is prepended to the Error field, safely preserving any diagnostic output the child process wrote before termination.
Run As Admin
Standard output capture is physically impossible when "Run As Admin" is checked due to Windows UAC process isolation.
| Pin | Direction | Purpose |
|---|---|---|
WorldContextObject | Input | Async action registration context. |
Command | Input | Command text executed by the selected shell. |
Options | Input | Shell, elevation, hidden mode, output capture, timeout, and working-directory settings. |
Then | Output | Continues immediately after the async action is created. |
On Success | Output | Fires strictly when the OS ExitCode is 0. |
On Fail | Output | Fires when the command crashes, times out, fails to start, or returns a non-zero exit code. |
Result | Output | FWNTCommandResult returned with the success or fail pin. |
#include "HardwareInfoLibrary.h"
// Define these functions in your header file
// UFUNCTION() void HandleCommandSuccess(FWNTCommandResult Result);
// UFUNCTION() void HandleCommandFail(FWNTCommandResult Result);
void AMySystemHelper::ExecuteAsyncCommand()
{
FWNTCommandOptions Options;
Options.Shell = EWNTCommandShell::PowerShell;
Options.bHidden = true;
Options.bCaptureOutput = true;
Options.TimeoutSeconds = 5.0f;
UAsyncRunCommandAction* Action = UAsyncRunCommandAction::RunCommandAsync(this, TEXT("Get-Location"), Options);
Action->OnSuccess.AddDynamic(this, &AMySystemHelper::HandleCommandSuccess);
Action->OnFail.AddDynamic(this, &AMySystemHelper::HandleCommandFail);
}FWNTCommandOptions Fields
| Field | Description |
|---|---|
Shell | Defines which shell to execute (CMD or PowerShell). |
bRunAsAdmin | Whether to execute the command with elevated privileges via UAC. |
bHidden | Hides the console window during execution. |
bCaptureOutput | Captures standard output and standard error for the result. |
TimeoutSeconds | Maximum time in seconds before the process is forcefully killed. |
WorkingDirectory | The directory path to run the command in. |
FWNTCommandResult Fields
| Field | Description |
|---|---|
ExitCode | The exit code returned by the process upon completion. |
TextOutput | The standard output text printed by the command. |
Error | The standard error text, or warnings if the command timed out. |
Last updated on