/// <summary> /// /// </summary> /// <param name="startInfo"></param> /// <returns></returns> internal static WardenProcess LaunchWin32App(WardenStartInfo startInfo) { if (!new FileInfo(startInfo.FileName).Exists) { throw new WardenLaunchException($"Unable to launch {startInfo.FileName} -- the file is missing."); } if (startInfo.AsUser) { if (!Api.StartProcessAndBypassUac(startInfo.FileName, startInfo.Arguments, startInfo.WorkingDirectory, out var procInfo)) { throw new WardenLaunchException(string.Format(Resources.Exception_Process_Not_Start, startInfo.FileName, startInfo.Arguments)); } return(WardenProcess.GetProcessFromId((int)procInfo.dwProcessId, startInfo.Filters)); } var processStartInfo = new ProcessStartInfo { FileName = startInfo.FileName, Arguments = startInfo.Arguments, WorkingDirectory = startInfo.WorkingDirectory, UseShellExecute = true }; using (var process = Process.Start(processStartInfo)) { if (process == null) { throw new WardenLaunchException(Resources.Exception_Process_Not_Launched_Unknown); } return(WardenProcess.GetProcessFromId(process.Id, startInfo.Filters)); } }
/// <summary> /// Combines the Package Family Name and Application ID into a valid AUMID string and then launches the app. /// </summary> /// <param name="startInfo"></param> /// <returns>If the app is launched successfully a WardenProcess is returned.</returns> internal static WardenProcess LaunchApp(WardenStartInfo startInfo) { var aumid = $"{startInfo.PackageFamilyName}!{startInfo.ApplicationId}"; var processId = Launch(aumid, startInfo.Arguments); if (processId <= 0) { throw new WardenLaunchException(string.Format(Resources.Exception_Could_Not_Find_Process_Id, aumid)); } return(WardenProcess.GetProcessFromId(processId, startInfo.Filters)); }
private static async Task Start() { WardenManager.Initialize(); Console.Write("Enter the process ID: "); var processId = int.Parse(Console.ReadLine()); var test = WardenProcess.GetProcessFromId(processId); test.OnProcessAdded += delegate(object sender, ProcessAddedEventArgs args) { if (args.ParentId == test.Id) { Console.WriteLine($"Added child {args.Name}({args.Id}) to root process {test.Name}({test.Id})"); } else { var parentInfo = test.FindChildById(args.ParentId); if (parentInfo != null) { Console.WriteLine($"Added child process {args.Name}({args.Id}) to child {parentInfo.Name}({parentInfo.Id})"); } } }; test.OnStateChange += delegate(object sender, StateEventArgs args) { Console.WriteLine($"---\nName: {test.Name}\nId: {test.Id}\nstate changed to {args.State}\n---"); }; test.OnChildStateChange += delegate(object sender, StateEventArgs args) { var childInfo = test.FindChildById(args.Id); if (childInfo != null) { Console.WriteLine($"---\nName: {childInfo.Name}\nId: {childInfo.Id}\nParentId:{childInfo.ParentId}\nstated changed to {args.State}\n---"); } }; Console.WriteLine($"Hooked into {test.Name}({test.Id})"); Console.Read(); Console.WriteLine("Start notepad"); var wardenTest = await WardenProcess.Start("notepad.exe", string.Empty, ProcessTypes.Win32); if (wardenTest != null) { wardenTest.OnStateChange += delegate(object sender, StateEventArgs args) { Console.WriteLine($"---\nName: {wardenTest.Name}\nId: {wardenTest.Id}\nstate changed to {args.State}\n---"); }; } Console.ReadKey(true); }
public async Task <WardenProcess> Launch(string path, string arguments, bool asUser) { if (asUser) { var formattedPath = $"{path} {arguments}"; if (Api.StartProcessAndBypassUac(formattedPath, out var procInfo) && procInfo.dwProcessId > 0) { return(WardenProcess.GetProcessFromId((int)procInfo.dwProcessId)); } } else { return(await Launch(path, arguments)); } return(null); }
/// <summary> /// Attempts to create a process outside of session zero. /// </summary> /// <param name="startInfo"></param> /// <returns></returns> internal static WardenProcess CreateProcessAsUser(WardenStartInfo startInfo) { if (!new FileInfo(startInfo.FileName).Exists) { throw new WardenLaunchException($"Unable to launch {startInfo.FileName} -- the file is missing."); } if (startInfo.RaisePrivileges) { if (Api.StartProcessAsPrivilegedUser(startInfo.FileName, startInfo.Arguments, startInfo.WorkingDirectory, out var privInfo)) { return(WardenProcess.GetProcessFromId(privInfo, startInfo.Filters, startInfo.Track)); } throw new WardenLaunchException("Unable to start process as privileged user"); } if (Api.StartProcessAsUser(startInfo.FileName, startInfo.Arguments, startInfo.WorkingDirectory, out var procInfo)) { return(WardenProcess.GetProcessFromId(procInfo, startInfo.Filters, startInfo.Track)); } throw new WardenLaunchException("Unable to start process as user"); }
private static async Task Start() { WardenManager.Initialize(new WardenOptions { CleanOnExit = true, DeepKill = true, ReadFileHeaders = true }); Console.Write("Enter the process ID: "); var processId = int.Parse(Console.ReadLine()); var test = WardenProcess.GetProcessFromId(processId); if (test != null) { test.OnProcessAdded += delegate(object sender, ProcessAddedEventArgs args) { if (args.ParentId == test.Id) { Console.WriteLine($"Added child {args.Name}({args.Id}) to root process {test.Name}({test.Id})"); } else { var parentInfo = test.FindChildById(args.ParentId); if (parentInfo != null) { Console.WriteLine($"Added child process {args.Name}({args.Id}) to child {parentInfo.Name}({parentInfo.Id})"); } } }; test.OnStateChange += delegate(object sender, StateEventArgs args) { Console.WriteLine($"---\nName: {test.Name}\nId: {test.Id}\nstate changed to {args.State}\n---"); }; test.OnChildStateChange += delegate(object sender, StateEventArgs args) { var childInfo = test.FindChildById(args.Id); if (childInfo != null) { Console.WriteLine($"---\nName: {childInfo.Name}\nId: {childInfo.Id}\nParentId:{childInfo.ParentId}\nstated changed to {args.State}\n---"); } }; Console.WriteLine($"Hooked into {test.Name}({test.Id})"); Console.Read(); Console.WriteLine(JsonConvert.SerializeObject(test, Formatting.Indented)); test.Kill(); } Console.WriteLine("Start notepad"); var wardenTest = await WardenProcess.Start("notepad", string.Empty, null); if (wardenTest != null) { wardenTest.OnStateChange += delegate(object sender, StateEventArgs args) { Console.WriteLine($"---\nName: {wardenTest.Name}\nId: {wardenTest.Id}\nstate changed to {args.State}\n---"); }; } Console.ReadKey(true); }
public TestWardenOnTestProcess() { WardenManager.Initialize(true); _currentProcess = WardenProcess.GetProcessFromId(Process.GetCurrentProcess().Id); }