Table of Contents

Class PH

Namespace
SunamoWinStd
Assembly
SunamoWinStd.dll

Process helper class for running and managing system processes.

public class PH
Inheritance
PH
Inherited Members
Extension Methods

Methods

ExecCmd(string)

Executes a command via cmd.exe.

public static bool ExecCmd(string command)

Parameters

command string

The command to execute.

Returns

bool

True if the process completed without output to stderr.

ExecCmd(string, out string, bool)

Executes command via cmd.exe and captures output.

public static bool ExecCmd(string command, out string output, bool isTransferringEnvVars = false)

Parameters

command string

Command to be executed.

output string

Output which the application produced.

isTransferringEnvVars bool

True if retaining PATH environment variable from executed command.

Returns

bool

True if process exited with empty error output.

ExistsOnPath(string)

Checks if an executable exists on the system PATH.

public static bool ExistsOnPath(string fileName)

Parameters

fileName string

The file name to check.

Returns

bool

True if the file exists on PATH.

FindProcessesWhichOccupyFileHandleExe(ILogger, string, bool)

Finds processes that occupy a file handle using handle64.exe. Alternative is FileUtil.WhoIsLocking.

public static List<Process> FindProcessesWhichOccupyFileHandleExe(ILogger logger, string fileName, bool isThrowingOnError = true)

Parameters

logger ILogger

Logger instance.

fileName string

The file name to check.

isThrowingOnError bool

Whether to throw if handle64.exe fails.

Returns

List<Process>

List of processes occupying the file handle.

GetFullPath(string)

Gets the full path of a file by searching the system PATH.

public static string? GetFullPath(string fileName)

Parameters

fileName string

The file name to find.

Returns

string

Full path if found, null otherwise.

GetProcessesNames(bool)

Gets names of all running processes.

public static List<string> GetProcessesNames(bool isLowerCase)

Parameters

isLowerCase bool

Whether to convert names to lower case.

Returns

List<string>

List of process names.

IsAlreadyRunning(string)

Checks if a process with the given name is already running (more than one instance).

public static bool IsAlreadyRunning(string name)

Parameters

name string

The process name to check.

Returns

bool

True if more than one instance is running.

KillProcess(Process)

Kills the specified process.

public static void KillProcess(Process process)

Parameters

process Process

The process to kill.

NormalizeUri(string)

Normalizes a URI by replacing URL-encoded quotes.

public static string NormalizeUri(string uri)

Parameters

uri string

The URI to normalize.

Returns

string

The normalized URI.

ProcessesWithNameContains(string)

Returns names of processes whose name contains the specified string.

public static List<string> ProcessesWithNameContains(string name)

Parameters

name string

The substring to search for in process names.

Returns

List<string>

List of matching process names.

RunFromPath(ILogger, string, string, bool, bool)

Runs an executable found on the system PATH. Returns standard error or output if everything went well.

public static string? RunFromPath(ILogger logger, string exe, string arguments, bool isWithOutput, bool isThrowingOnError = false)

Parameters

logger ILogger

Logger instance for diagnostics.

exe string

Executable name to find on PATH.

arguments string

Arguments to pass to the executable.

isWithOutput bool

Whether to capture and return output.

isThrowingOnError bool

Whether to throw if the executable is not found.

Returns

string

Process output or null if not found.

RunFromPath3(string, string)

Runs an executable found on PATH. The executable must be on PATH.

public static void RunFromPath3(string exe, string fileWithoutQm)

Parameters

exe string

The executable name.

fileWithoutQm string

The file path to pass as argument (will be wrapped in quotes).

RunFromPathBetter(string, string)

Runs an executable from the system PATH with better extension detection.

public static string RunFromPathBetter(string exe, string arguments)

Parameters

exe string

The executable name.

arguments string

Arguments to pass.

Returns

string

Process output.

RunWithOutput(ProcessStartInfo, bool)

Runs a process with the given start info and returns its output.

public static string RunWithOutput(ProcessStartInfo processStartInfo, bool isTransferringEnvVars = false)

Parameters

processStartInfo ProcessStartInfo

Process start information.

isTransferringEnvVars bool

Whether to transfer environment variables from the process output.

Returns

string

Combined standard output and error.

RunWithOutput(string, string)

Runs an executable and returns its output.

public static string RunWithOutput(string exe, string arguments)

Parameters

exe string

Executable path or name.

arguments string

Arguments to pass.

Returns

string

Combined standard output and error.

ShutdownProcessWhichOccupyFileHandleExe(ILogger, string)

Shuts down processes that occupy a file handle. Alternative is FileUtil.WhoIsLocking.

public static void ShutdownProcessWhichOccupyFileHandleExe(ILogger logger, string fileName)

Parameters

logger ILogger

Logger instance.

fileName string

The file name to check.

Start(string)

Starts a command via cmd.exe. The executable must be on PATH.

public static void Start(string parameter)

Parameters

parameter string

The command parameter to execute.

Start(string, string)

Starts an executable with arguments via cmd.exe.

public static void Start(string exe, string arguments)

Parameters

exe string

The executable to run.

arguments string

Arguments for the executable.

StartHidden(string, string)

Starts a hidden command process in the specified working directory.

public static void StartHidden(string parameter, string workingDirectory)

Parameters

parameter string

The command parameter to execute.

workingDirectory string

The working directory for the process.

Terminate(string)

Terminates all processes with the specified name.

public static int Terminate(string name)

Parameters

name string

The process name to terminate.

Returns

int

Number of processes terminated.

TerminateProcessesWithName(string)

Terminates processes with the exact name (without extensions, all lower case).

public static int TerminateProcessesWithName(string name)

Parameters

name string

The process name to terminate.

Returns

int

Number of processes terminated.

TerminateProcessesWithNameContains(string)

Terminates all processes whose name contains the specified string.

public static int TerminateProcessesWithNameContains(string name)

Parameters

name string

The substring to search for in process names.

Returns

int

Number of processes terminated.