[WIP] Nearly ready to test the new process utils

This commit is contained in:
Terry MacDonald 2021-11-21 10:29:06 +13:00
parent ba2e0afb71
commit c9c9fcc8b4
8 changed files with 26 additions and 11 deletions

View File

@ -11,6 +11,7 @@ using System.Xml.XPath;
using System.Web;
using System.Diagnostics;
using Newtonsoft.Json;
using DisplayMagician.Processes;
namespace DisplayMagician.GameLibraries
{

View File

@ -11,6 +11,7 @@ using System.Xml.XPath;
using System.Web;
using System.Diagnostics;
using Newtonsoft.Json;
using DisplayMagician.Processes;
namespace DisplayMagician.GameLibraries
{

View File

@ -11,6 +11,7 @@ using System.Xml.XPath;
using System.Web;
using System.Diagnostics;
using System.Text;
using DisplayMagician.Processes;
namespace DisplayMagician.GameLibraries
{

View File

@ -8,6 +8,7 @@ using Microsoft.Win32;
using System.IO;
using System.Security;
using System.Diagnostics;
using DisplayMagician.Processes;
namespace DisplayMagician.GameLibraries
{

View File

@ -10,6 +10,7 @@ using ProtoBuf;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;
using System.Globalization;
using DisplayMagician.Processes;
namespace DisplayMagician.GameLibraries
{
@ -915,7 +916,8 @@ namespace DisplayMagician.GameLibraries
{
address += "/0";
}
List<Process> gameProcesses = ProcessUtils.StartProcess(address, null, processPriority);
//List<Process> gameProcesses = ProcessUtils.StartProcess(address, null, processPriority);
List<Process> gameProcesses = ProcessUtils.StartProcess(address, "", ProcessPriority.Normal);
return gameProcesses;
}

View File

@ -59,6 +59,13 @@ namespace DisplayMagician.Processes
List<Process> runningProcesses = new List<Process>();
Process process = null;
bool usingChildProcess = false;
if (TryExecute_AutoImpersonate(executable, arguments, out process))
{
logger.Trace($"ProcessUtils/StartProcess: {executable} {arguments} has successfully been started (ID: {process.Id})");
runningProcesses.Add(process);
}
return runningProcesses;
}
public static List<Process> GetChildProcesses(Process process)
@ -259,11 +266,11 @@ namespace DisplayMagician.Processes
/// <param name="priorityClass">Process priority</param>
/// <param name="maxWaitMs">Maximum time to wait for completion</param>
/// <returns><c>true</c> if process was executed and finished correctly</returns>
public static bool TryExecute_AutoImpersonate(string executable, string arguments, ProcessPriorityClass priorityClass = ProcessPriorityClass.Normal, int maxWaitMs = 1000)
public static bool TryExecute_AutoImpersonate(string executable, string arguments, out Process process, ProcessPriorityClass priorityClass = ProcessPriorityClass.Normal, int maxWaitMs = 1000)
{
return IsImpersonated ?
TryExecute_Impersonated(executable, arguments, priorityClass, maxWaitMs) :
TryExecute(executable, arguments, priorityClass, maxWaitMs);
TryExecute_Impersonated(executable, arguments, out process, priorityClass, maxWaitMs) :
TryExecute(executable, arguments, out process, priorityClass, maxWaitMs);
}
/// <summary>
@ -275,16 +282,16 @@ namespace DisplayMagician.Processes
/// <param name="priorityClass">Process priority</param>
/// <param name="maxWaitMs">Maximum time to wait for completion</param>
/// <returns><c>true</c> if process was executed and finished correctly</returns>
public static bool TryExecute_Impersonated(string executable, string arguments, ProcessPriorityClass priorityClass = ProcessPriorityClass.Normal, int maxWaitMs = 1000)
public static bool TryExecute_Impersonated(string executable, string arguments, out Process process, ProcessPriorityClass priorityClass = ProcessPriorityClass.Normal, int maxWaitMs = 1000)
{
IntPtr userToken;
process = null;
if (!ImpersonationHelper.GetTokenByProcess(out userToken, true))
return false;
try
{
Process unused;
//return TryExecute_Impersonated(executable, arguments, userToken, false, out unused, priorityClass, maxWaitMs);
return TryExecute_Impersonated(executable, arguments, userToken, out unused, priorityClass, maxWaitMs);
return TryExecute_Impersonated(executable, arguments, userToken, out process, priorityClass, maxWaitMs);
}
finally
{

View File

@ -26,8 +26,8 @@ using System.Resources;
[assembly: Guid("e4ceaf5e-ad01-4695-b179-31168eb74c48")]
// Version information
[assembly: AssemblyVersion("2.1.0.281")]
[assembly: AssemblyFileVersion("2.1.0.281")]
[assembly: AssemblyVersion("2.1.0.282")]
[assembly: AssemblyFileVersion("2.1.0.282")]
[assembly: NeutralResourcesLanguageAttribute( "en" )]
[assembly: CLSCompliant(true)]

View File

@ -936,6 +936,7 @@ namespace DisplayMagician
List<Process> processesCreated = new List<Process>();
try
{
//processesCreated = ProcessUtils.StartProcess(processToStart.Executable, processToStart.Arguments, processToStart.ProcessPriority);
processesCreated = ProcessUtils.StartProcess(processToStart.Executable, processToStart.Arguments, processToStart.ProcessPriority);
// Record the program we started so we can close it later
@ -1924,14 +1925,15 @@ namespace DisplayMagician
{
//Processes.PROCESS_INFORMATION processInfo;
//if (ProcessUtils.CreateProcessWithPriority(stopProg.Executable, stopProg.Arguments, TranslatePriorityToClass(stopProg.ProcessPriority), out processInfo))
if (ProcessUtils.StartProcess(stopProg.Executable, stopProg.Arguments, TranslatePriorityToClass(stopProg.ProcessPriority), out processInfo))
ProcessUtils.StartProcess(stopProg.Executable, stopProg.Arguments, ProcessPriority.Normal);
/*if ()
{
logger.Trace($"ShortcutRepository/RunShortcut: Successfully started Stop Program {stopProg.Executable} {stopProg.Arguments}");
}
else
{
logger.Warn($"ShortcutRepository/RunShortcut: Unable to start Stop Program {stopProg.Executable} {stopProg.Arguments}");
}
}*/
}
catch (Exception ex)
{