Hinzufügen der Möglichkeit ein Programmstart auf dem Client durch die RDP Sitzung zu triggern
This commit is contained in:
+28
-28
@@ -122,9 +122,9 @@ namespace
|
||||
std::wstring commandLine;
|
||||
};
|
||||
|
||||
bool BuildLaunchCommand(const hook::HookConfig& config, LaunchCommand& command)
|
||||
bool BuildLaunchCommand(const hook::LaunchConfig& config, LaunchCommand& command)
|
||||
{
|
||||
const std::wstring extension = GetExtensionLower(config.scriptPath);
|
||||
const std::wstring extension = GetExtensionLower(config.path);
|
||||
|
||||
if (extension == L".bat" || extension == L".cmd")
|
||||
{
|
||||
@@ -139,7 +139,7 @@ namespace
|
||||
comspec = systemRoot + L"\\System32\\cmd.exe";
|
||||
}
|
||||
|
||||
std::wstring inner = QuoteWindowsArgument(config.scriptPath);
|
||||
std::wstring inner = QuoteWindowsArgument(config.path);
|
||||
if (!config.arguments.empty())
|
||||
{
|
||||
inner += L" " + config.arguments;
|
||||
@@ -162,7 +162,7 @@ namespace
|
||||
command.application = powershell;
|
||||
command.commandLine = QuoteWindowsArgument(powershell) +
|
||||
L" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass -File " +
|
||||
QuoteWindowsArgument(config.scriptPath);
|
||||
QuoteWindowsArgument(config.path);
|
||||
if (!config.arguments.empty())
|
||||
{
|
||||
command.commandLine += L" " + config.arguments;
|
||||
@@ -172,8 +172,8 @@ namespace
|
||||
|
||||
if (extension == L".exe")
|
||||
{
|
||||
command.application = config.scriptPath;
|
||||
command.commandLine = QuoteWindowsArgument(config.scriptPath);
|
||||
command.application = config.path;
|
||||
command.commandLine = QuoteWindowsArgument(config.path);
|
||||
if (!config.arguments.empty())
|
||||
{
|
||||
command.commandLine += L" " + config.arguments;
|
||||
@@ -217,37 +217,37 @@ namespace hook
|
||||
return process_ != nullptr;
|
||||
}
|
||||
|
||||
bool ProcessLauncher::Start(const HookConfig& config)
|
||||
bool ProcessLauncher::Start(const LaunchConfig& config, bool loggingEnabled, const std::wstring& sourceName)
|
||||
{
|
||||
CleanupExitedProcess();
|
||||
if (process_ != nullptr)
|
||||
{
|
||||
Log(config.enableLogging, L"Script ist für diese MSTSC-Instanz bereits aktiv (PID " + std::to_wstring(processId_) + L").");
|
||||
Log(loggingEnabled, sourceName + L" ist für diese MSTSC-Instanz bereits aktiv (PID " + std::to_wstring(processId_) + L").");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (config.scriptPath.empty())
|
||||
if (config.path.empty())
|
||||
{
|
||||
Log(config.enableLogging, L"Kein ScriptPath konfiguriert; Start übersprungen.");
|
||||
Log(loggingEnabled, L"Kein Pfad für " + sourceName + L" konfiguriert; Start übersprungen.");
|
||||
return false;
|
||||
}
|
||||
|
||||
DWORD attributes = GetFileAttributesW(config.scriptPath.c_str());
|
||||
DWORD attributes = GetFileAttributesW(config.path.c_str());
|
||||
if (attributes == INVALID_FILE_ATTRIBUTES || (attributes & FILE_ATTRIBUTE_DIRECTORY) != 0)
|
||||
{
|
||||
Log(config.enableLogging, L"Script wurde nicht gefunden: " + config.scriptPath);
|
||||
Log(loggingEnabled, sourceName + L" wurde nicht gefunden: " + config.path);
|
||||
return false;
|
||||
}
|
||||
|
||||
LaunchCommand command;
|
||||
if (!BuildLaunchCommand(config, command))
|
||||
{
|
||||
Log(config.enableLogging, L"Nicht unterstützter Script-/Dateityp: " + config.scriptPath);
|
||||
Log(loggingEnabled, L"Nicht unterstützter Datei-/Programmtyp für " + sourceName + L": " + config.path);
|
||||
return false;
|
||||
}
|
||||
|
||||
std::wstring workingDirectory = config.workingDirectory.empty()
|
||||
? ParentDirectory(config.scriptPath)
|
||||
? ParentDirectory(config.path)
|
||||
: config.workingDirectory;
|
||||
|
||||
HANDLE duplicateMutex = nullptr;
|
||||
@@ -257,19 +257,19 @@ namespace hook
|
||||
sa.nLength = sizeof(sa);
|
||||
sa.bInheritHandle = TRUE;
|
||||
|
||||
std::wstring mutexName = MutexNameForScript(config.scriptPath);
|
||||
std::wstring mutexName = MutexNameForScript(config.path);
|
||||
duplicateMutex = CreateMutexW(&sa, FALSE, mutexName.c_str());
|
||||
if (duplicateMutex == nullptr)
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
Log(config.enableLogging, L"Mehrfachstart-Schutz konnte nicht erstellt werden: " + FormatWin32Error(error));
|
||||
Log(loggingEnabled, L"Mehrfachstart-Schutz konnte nicht erstellt werden: " + FormatWin32Error(error));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (GetLastError() == ERROR_ALREADY_EXISTS)
|
||||
{
|
||||
CloseHandle(duplicateMutex);
|
||||
Log(config.enableLogging, L"Ein Receiver mit demselben ScriptPath läuft bereits; kein weiterer Start.");
|
||||
Log(loggingEnabled, sourceName + L" läuft laut Mehrfachstart-Schutz bereits; kein weiterer Start.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -305,7 +305,7 @@ namespace hook
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
CloseHandle(duplicateMutex);
|
||||
Log(config.enableLogging, L"Prozessattributliste konnte nicht initialisiert werden: " + FormatWin32Error(error));
|
||||
Log(loggingEnabled, L"Prozessattributliste konnte nicht initialisiert werden: " + FormatWin32Error(error));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -322,7 +322,7 @@ namespace hook
|
||||
DWORD error = GetLastError();
|
||||
DeleteProcThreadAttributeList(startup.lpAttributeList);
|
||||
CloseHandle(duplicateMutex);
|
||||
Log(config.enableLogging, L"Handle-Vererbung konnte nicht vorbereitet werden: " + FormatWin32Error(error));
|
||||
Log(loggingEnabled, L"Handle-Vererbung konnte nicht vorbereitet werden: " + FormatWin32Error(error));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -371,7 +371,7 @@ namespace hook
|
||||
if (!created)
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
Log(config.enableLogging, L"Scriptstart fehlgeschlagen: " + FormatWin32Error(error));
|
||||
Log(loggingEnabled, sourceName + L" konnte nicht gestartet werden: " + FormatWin32Error(error));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -379,14 +379,14 @@ namespace hook
|
||||
process_ = pi.hProcess;
|
||||
processId_ = pi.dwProcessId;
|
||||
|
||||
Log(config.enableLogging,
|
||||
L"Script gestartet. PID=" + std::to_wstring(processId_) +
|
||||
L", Script=" + config.scriptPath +
|
||||
Log(loggingEnabled,
|
||||
sourceName + L" gestartet. PID=" + std::to_wstring(processId_) +
|
||||
L", Pfad=" + config.path +
|
||||
(config.arguments.empty() ? L"" : L", Argumente=" + config.arguments));
|
||||
return true;
|
||||
}
|
||||
|
||||
void ProcessLauncher::Stop(bool loggingEnabled)
|
||||
void ProcessLauncher::Stop(bool loggingEnabled, const std::wstring& sourceName)
|
||||
{
|
||||
CleanupExitedProcess();
|
||||
if (process_ == nullptr)
|
||||
@@ -398,11 +398,11 @@ namespace hook
|
||||
if (!TerminateProcess(process_, 0))
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
Log(loggingEnabled, L"Scriptprozess PID " + std::to_wstring(pid) + L" konnte nicht beendet werden: " + FormatWin32Error(error));
|
||||
Log(loggingEnabled, sourceName + L" PID " + std::to_wstring(pid) + L" konnte nicht beendet werden: " + FormatWin32Error(error));
|
||||
}
|
||||
else
|
||||
{
|
||||
Log(loggingEnabled, L"Beenden des Scriptprozesses PID " + std::to_wstring(pid) + L" wurde bei RDP-Trennung angefordert.");
|
||||
Log(loggingEnabled, L"Beenden von " + sourceName + L" PID " + std::to_wstring(pid) + L" wurde angefordert.");
|
||||
}
|
||||
|
||||
CloseHandle(process_);
|
||||
@@ -410,7 +410,7 @@ namespace hook
|
||||
processId_ = 0;
|
||||
}
|
||||
|
||||
void ProcessLauncher::Detach(bool loggingEnabled)
|
||||
void ProcessLauncher::Detach(bool loggingEnabled, const std::wstring& sourceName)
|
||||
{
|
||||
CleanupExitedProcess();
|
||||
if (process_ == nullptr)
|
||||
@@ -418,7 +418,7 @@ namespace hook
|
||||
return;
|
||||
}
|
||||
|
||||
Log(loggingEnabled, L"MSTSC beendet Plugin; Script PID " + std::to_wstring(processId_) + L" läuft weiter.");
|
||||
Log(loggingEnabled, L"MSTSC beendet Plugin; " + sourceName + L" PID " + std::to_wstring(processId_) + L" läuft weiter.");
|
||||
CloseHandle(process_);
|
||||
process_ = nullptr;
|
||||
processId_ = 0;
|
||||
|
||||
Reference in New Issue
Block a user