NanoByte.Common
Static Public Member Functions | List of all members
NanoByte.Common.ProcessUtils Class Reference

Provides methods for launching child processes. More...

Static Public Member Functions

static Process Start ([NotNull] this ProcessStartInfo startInfo)
 Starts a new Process and runs it in parallel with this one. Handles and wraps Win32Exceptions. More...
 
static Process Start ([NotNull] string fileName, [NotNull] params string[] arguments)
 Starts a new Process and runs it in parallel with this one. Handles and wraps Win32Exceptions. More...
 
static int Run ([NotNull] this ProcessStartInfo startInfo)
 Starts a new Process and waits for it to complete. Handles and wraps Win32Exceptions. More...
 
static ProcessStartInfo Assembly ([NotNull] string name, [NotNull] params string[] arguments)
 Creates a ProcessStartInfo for launching an assembly located in Locations.InstallBase. More...
 
static ProcessStartInfo AsAdmin ([NotNull] 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...
 

Detailed Description

Provides methods for launching child processes.

Member Function Documentation

◆ AsAdmin()

static ProcessStartInfo NanoByte.Common.ProcessUtils.AsAdmin ( [NotNull] 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 ( [NotNull] string  name,
[NotNull] 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.

◆ Run()

static int NanoByte.Common.ProcessUtils.Run ( [NotNull] 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 ( [NotNull] 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; 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 ( [NotNull] string  fileName,
[NotNull] 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.

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