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
commandstringThe 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
commandstringCommand to be executed.
outputstringOutput which the application produced.
isTransferringEnvVarsboolTrue 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
fileNamestringThe 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
loggerILoggerLogger instance.
fileNamestringThe file name to check.
isThrowingOnErrorboolWhether to throw if handle64.exe fails.
Returns
GetFullPath(string)
Gets the full path of a file by searching the system PATH.
public static string? GetFullPath(string fileName)
Parameters
fileNamestringThe 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
isLowerCaseboolWhether to convert names to lower case.
Returns
IsAlreadyRunning(string)
Checks if a process with the given name is already running (more than one instance).
public static bool IsAlreadyRunning(string name)
Parameters
namestringThe 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
processProcessThe process to kill.
NormalizeUri(string)
Normalizes a URI by replacing URL-encoded quotes.
public static string NormalizeUri(string uri)
Parameters
uristringThe 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
namestringThe substring to search for in process names.
Returns
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
loggerILoggerLogger instance for diagnostics.
exestringExecutable name to find on PATH.
argumentsstringArguments to pass to the executable.
isWithOutputboolWhether to capture and return output.
isThrowingOnErrorboolWhether 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
exestringThe executable name.
fileWithoutQmstringThe 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
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
processStartInfoProcessStartInfoProcess start information.
isTransferringEnvVarsboolWhether 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
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
Start(string)
Starts a command via cmd.exe. The executable must be on PATH.
public static void Start(string parameter)
Parameters
parameterstringThe command parameter to execute.
Start(string, string)
Starts an executable with arguments via cmd.exe.
public static void Start(string exe, string arguments)
Parameters
StartHidden(string, string)
Starts a hidden command process in the specified working directory.
public static void StartHidden(string parameter, string workingDirectory)
Parameters
parameterstringThe command parameter to execute.
workingDirectorystringThe working directory for the process.
Terminate(string)
Terminates all processes with the specified name.
public static int Terminate(string name)
Parameters
namestringThe 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
namestringThe 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
namestringThe substring to search for in process names.
Returns
- int
Number of processes terminated.