NanoByte.Common  2.10.5
NanoByte.Common.ProcessUtils Class Reference

Provides methods for launching child processes. More...

Static Public Member Functions

static Process Start (this ProcessStartInfo startInfo)
 Starts a new Process and runs it in parallel with this one. Handles and wraps Win32Exceptions. More...
 
static Process Start (string fileName, params string[] arguments)
 Starts a new Process and runs it in parallel with this one. Handles and wraps Win32Exceptions. More...
 
static int Run (this ProcessStartInfo startInfo)
 Starts a new Process and waits for it to complete. Handles and wraps Win32Exceptions. More...
 
static ProcessStartInfo Assembly (string name, params string[] arguments)
 Creates a ProcessStartInfo for launching an assembly located in Locations.InstallBase. More...
 
static ProcessStartInfo AsAdmin (this ProcessStartInfo startInfo)
 Modifies a ProcessStartInfo to request elevation to Administrator on Windows using UAC. More...
 
static void SanitizeEnvironmentVariables ()
 Workaround for environment variable problems, such variable names that differ only in case when running on Windows. More...
 
static string JoinEscapeArguments (this IEnumerable< string > parts)
 Combines multiple strings into one for use as a command-line argument using EscapeArgument. More...
 
static string EscapeArgument (this string value)
 Escapes a string for use as a command-line argument, making sure it is encapsulated within " if it contains whitespace characters. More...
 
static string ToCommandLine (this ProcessStartInfo startInfo)
 Converts a start into a command-line with proper escaping. More...
 
static ProcessStartInfo FromCommandLine (string commandLine)
 Converts a command-line into a start info. More...
 
static void Deconstruct (this ProcessStartInfo startInfo, out string fileName, out string arguments)
 Deconstructs a ProcessStartInfo like a tuple. More...
 

Detailed Description

Provides methods for launching child processes.

Member Function Documentation

◆ AsAdmin()

static ProcessStartInfo NanoByte.Common.ProcessUtils.AsAdmin ( this ProcessStartInfo  startInfo)
inlinestatic

Modifies a ProcessStartInfo to request elevation to Administrator on Windows using UAC.

Exceptions
PlatformNotSupportedExceptionThe current operating system does not support UAC or it is disabled..

◆ Assembly()

static ProcessStartInfo NanoByte.Common.ProcessUtils.Assembly ( string  name,
params string[]  arguments 
)
inlinestatic

Creates a ProcessStartInfo for launching an assembly located in Locations.InstallBase.

Parameters
nameThe name of the assembly to launch (without the file extension).
argumentsThe command-line arguments to pass to the assembly.

◆ Deconstruct()

static void NanoByte.Common.ProcessUtils.Deconstruct ( this ProcessStartInfo  startInfo,
out string  fileName,
out string  arguments 
)
inlinestatic

Deconstructs a ProcessStartInfo like a tuple.

◆ EscapeArgument()

static string NanoByte.Common.ProcessUtils.EscapeArgument ( this string  value)
inlinestatic

Escapes a string for use as a command-line argument, making sure it is encapsulated within " if it contains whitespace characters.

◆ FromCommandLine()

static ProcessStartInfo NanoByte.Common.ProcessUtils.FromCommandLine ( string  commandLine)
inlinestatic

Converts a command-line into a start info.

◆ JoinEscapeArguments()

static string NanoByte.Common.ProcessUtils.JoinEscapeArguments ( this IEnumerable< string >  parts)
inlinestatic

Combines multiple strings into one for use as a command-line argument using EscapeArgument.

Parameters
partsThe strings to be combined.

◆ Run()

static int NanoByte.Common.ProcessUtils.Run ( this ProcessStartInfo  startInfo)
inlinestatic

Starts a new Process and waits for it to complete. Handles and wraps Win32Exceptions.

Returns
The exit code of the child process.
Exceptions
IOExceptionThere was a problem launching the executable.
FileNotFoundExceptionThe executable file could not be found.
NotAdminExceptionThe target process requires elevation but the UAC prompt could not be displayed because ProcessStartInfo.UseShellExecute is false.
OperationCanceledExceptionThe user was asked for intervention by the OS (e.g. a UAC prompt) and the user cancelled.

◆ SanitizeEnvironmentVariables()

static void NanoByte.Common.ProcessUtils.SanitizeEnvironmentVariables ( )
inlinestatic

Workaround for environment variable problems, such variable names that differ only in case when running on Windows.

Call this before any access to ProcessStartInfo.EnvironmentVariables to avoid ArgumentExceptions.

◆ Start() [1/2]

static Process NanoByte.Common.ProcessUtils.Start ( string  fileName,
params string[]  arguments 
)
inlinestatic

Starts a new Process and runs it in parallel with this one. Handles and wraps Win32Exceptions.

Parameters
fileNameThe path of the file to open or executable to launch.
argumentsThe command-line arguments to pass to the executable.
Returns
The newly launched process; null if an existing process was reused.
Exceptions
IOExceptionThere was a problem launching the executable.
FileNotFoundExceptionThe executable file could not be found.
NotAdminExceptionThe target process requires elevation but the UAC prompt could not be displayed because ProcessStartInfo.UseShellExecute is false.
OperationCanceledExceptionThe user was asked for intervention by the OS (e.g. a UAC prompt) and the user cancelled.

◆ Start() [2/2]

static Process NanoByte.Common.ProcessUtils.Start ( this ProcessStartInfo  startInfo)
inlinestatic

Starts a new Process and runs it in parallel with this one. Handles and wraps Win32Exceptions.

Returns
The newly launched process.
Exceptions
IOExceptionThere was a problem launching the executable.
FileNotFoundExceptionThe executable file could not be found.
NotAdminExceptionThe target process requires elevation but the UAC prompt could not be displayed because ProcessStartInfo.UseShellExecute is false.
OperationCanceledExceptionThe user was asked for intervention by the OS (e.g. a UAC prompt) and the user cancelled.

◆ ToCommandLine()

static string NanoByte.Common.ProcessUtils.ToCommandLine ( this ProcessStartInfo  startInfo)
inlinestatic

Converts a start into a command-line with proper escaping.


The documentation for this class was generated from the following file: