Hinzufügen der Möglichkeit ein Programmstart auf dem Client durch die RDP Sitzung zu triggern

This commit is contained in:
2026-08-11 09:52:49 +02:00
parent eec4f52b5a
commit ee88f1ff30
22 changed files with 1162 additions and 263 deletions
+29 -20
View File
@@ -4,24 +4,36 @@ namespace Plandent.MstscScriptHook.Configurator;
internal static class ScriptTestLauncher
{
public static Process Start(HookConfig config)
public static Process StartConnectionProgram(HookConfig config) => Start(
config.ScriptPath,
config.Arguments,
config.WorkingDirectory,
config.Hidden);
public static Process StartTriggerProgram(HookConfig config) => Start(
config.TriggerProgramPath,
config.TriggerArguments,
config.TriggerWorkingDirectory,
config.TriggerHidden);
private static Process Start(string configuredPath, string configuredArguments, string configuredWorkingDirectory, bool hidden)
{
string scriptPath = Environment.ExpandEnvironmentVariables(config.ScriptPath ?? string.Empty);
if (string.IsNullOrWhiteSpace(scriptPath) || !File.Exists(scriptPath))
string programPath = Environment.ExpandEnvironmentVariables(configuredPath ?? string.Empty);
if (string.IsNullOrWhiteSpace(programPath) || !File.Exists(programPath))
{
throw new FileNotFoundException("Das ausgewählte Script wurde nicht gefunden.", scriptPath);
throw new FileNotFoundException("Das ausgewählte Programm/Script wurde nicht gefunden.", programPath);
}
string extension = Path.GetExtension(scriptPath).ToLowerInvariant();
string workingDirectory = string.IsNullOrWhiteSpace(config.WorkingDirectory)
? Path.GetDirectoryName(scriptPath) ?? Environment.CurrentDirectory
: Environment.ExpandEnvironmentVariables(config.WorkingDirectory);
string extension = Path.GetExtension(programPath).ToLowerInvariant();
string workingDirectory = string.IsNullOrWhiteSpace(configuredWorkingDirectory)
? Path.GetDirectoryName(programPath) ?? Environment.CurrentDirectory
: Environment.ExpandEnvironmentVariables(configuredWorkingDirectory);
var startInfo = new ProcessStartInfo
{
UseShellExecute = false,
CreateNoWindow = config.Hidden,
WindowStyle = config.Hidden ? ProcessWindowStyle.Hidden : ProcessWindowStyle.Normal,
CreateNoWindow = hidden,
WindowStyle = hidden ? ProcessWindowStyle.Hidden : ProcessWindowStyle.Normal,
WorkingDirectory = workingDirectory
};
@@ -34,7 +46,7 @@ internal static class ScriptTestLauncher
startInfo.ArgumentList.Add("/D");
startInfo.ArgumentList.Add("/S");
startInfo.ArgumentList.Add("/C");
startInfo.ArgumentList.Add(BuildCmdCommand(scriptPath, config.Arguments));
startInfo.ArgumentList.Add(BuildCmdCommand(programPath, configuredArguments));
break;
case ".ps1":
@@ -49,13 +61,13 @@ internal static class ScriptTestLauncher
startInfo.ArgumentList.Add("-ExecutionPolicy");
startInfo.ArgumentList.Add("Bypass");
startInfo.ArgumentList.Add("-File");
startInfo.ArgumentList.Add(scriptPath);
AddRawArguments(startInfo, config.Arguments);
startInfo.ArgumentList.Add(programPath);
AddRawArguments(startInfo, configuredArguments);
break;
case ".exe":
startInfo.FileName = scriptPath;
AddRawArguments(startInfo, config.Arguments);
startInfo.FileName = programPath;
AddRawArguments(startInfo, configuredArguments);
break;
default:
@@ -66,9 +78,9 @@ internal static class ScriptTestLauncher
?? throw new InvalidOperationException("Der Testprozess konnte nicht gestartet werden.");
}
private static string BuildCmdCommand(string scriptPath, string? arguments)
private static string BuildCmdCommand(string programPath, string? arguments)
{
string command = QuoteForCmd(scriptPath);
string command = QuoteForCmd(programPath);
if (!string.IsNullOrWhiteSpace(arguments))
{
command += " " + arguments;
@@ -81,9 +93,6 @@ internal static class ScriptTestLauncher
return "\"" + value.Replace("\"", "\\\"") + "\"";
}
// Die GUI behandelt das Argumentfeld bewusst als Kommandozeilen-Argumentstring.
// Für den Test wird eine einfache Windows-Argumentzerlegung verwendet. Das Plugin selbst
// übergibt den String unverändert an cmd.exe/PowerShell bzw. an die EXE-Kommandozeile.
private static void AddRawArguments(ProcessStartInfo startInfo, string? raw)
{
if (string.IsNullOrWhiteSpace(raw))