Warden.NET is a simple to use library for managing processes and their states.
With Rainway we're tasked with launching thousands of different applications from various third parties. To ensure launching games was a smooth process for the user, we needed a reliable way to keep track of game states.
The System.Diagnostics.Process
class while useful does not have a concept for parent applications; while Windows itself does track parents, it does not track grandparents and processes can quickly become orphaned. Which is where Warden comes in.
Via Nuget
Install-Package Warden.NET
To initialize Warden inside your application, call the static initialization function. (Pass true
if you'd like Warden to kill all monitored processes on exit.)
WardenManager.Initialize(new WardenOptions
{
CleanOnExit = true,
DeepKill = true,
ReadFileHeaders = true
});
Warden processes are launched asynchronously and return null if it fails to launch.
If you wish to launch a Win32 application just call the following code.
var process = await WardenProcess.Start("G:/Games/steamapps/common/NieRAutomata/NieRAutomata.exe", string.empty, null);
Similarly, you can launch a UWP like so.
var process = await WardenProcess.StartUwp("Microsoft.Halo5Forge_8wekyb3d8bbwe", "!Ausar", string.Empty, null);
If you need to start a URI, that is also supported.
Pass the URI you wish to run, as well as the full path to the executable that should appear afterwards. This method will return an "empty" Warden object. The Id
of the object will update automatically when the target process launches.
var test = await WardenProcess.StartUriAsync("steam://run/107410", "G:/Games/steamapps/common/Arma 3/arma3launcher.exe", string.Empty, null, callback, token);
Or you can synchronously wait for a URI to start
var test = await WardenProcess.StartUri("steam://run/107410", "G:/Games/steamapps/common/Arma 3/arma3launcher.exe", string.Empty, null, token);
Finally, you can build a Warden process tree from an already running process like so
WardenProcess.GetProcessFromId(999);
You can subscribe to OnProcessAdded
to know when a process has been added to the tree, the OnStateChange
event to know when a process state has updated. Additionally you can subscribe to OnChildStateChange
to know when its children have had a change in state.
If you'd like to contribute we'll be happy to accept pull request. You can find a full example application in the repository.