From 850ea0d2115ddcc7e625d38e1511fddb14becc26 Mon Sep 17 00:00:00 2001 From: kervala Date: Tue, 2 Feb 2016 19:49:37 +0100 Subject: [PATCH] Changed: Detect .bat file in launchProgram and adapt syntax of CreateProcess --- code/nel/src/misc/common.cpp | 17 ++++++++++++++++- code/ryzom/client/src/login_patch.cpp | 6 +++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/code/nel/src/misc/common.cpp b/code/nel/src/misc/common.cpp index 6888dd24f..d586e4638 100644 --- a/code/nel/src/misc/common.cpp +++ b/code/nel/src/misc/common.cpp @@ -732,7 +732,22 @@ bool launchProgram(const std::string &programName, const std::string &arguments, SetEnvironmentVariable( SE_TRANSLATOR_IN_MAIN_MODULE, NULL ); } - BOOL res = CreateProcessA(programName.empty() ? NULL:programName.c_str(), (char*)arguments.c_str(), NULL, NULL, FALSE, CREATE_DEFAULT_ERROR_MODE | CREATE_NO_WINDOW, NULL, NULL, &si, &pi); + const char *sProgramName = programName.c_str(); + + std::string args; + + // a .bat file must have first parameter to NULL and use 2nd parameter to pass filename + if (CFile::getExtension(programName) == "bat") + { + sProgramName = NULL; + args = "\"" + programName + "\" " + arguments; + } + else + { + args = arguments; + } + + BOOL res = CreateProcessA(sProgramName, (char*)args.c_str(), NULL, NULL, FALSE, CREATE_DEFAULT_ERROR_MODE | CREATE_NO_WINDOW, NULL, NULL, &si, &pi); if (res) { diff --git a/code/ryzom/client/src/login_patch.cpp b/code/ryzom/client/src/login_patch.cpp index 68b29b687..898ee7d6d 100644 --- a/code/ryzom/client/src/login_patch.cpp +++ b/code/ryzom/client/src/login_patch.cpp @@ -938,14 +938,14 @@ void CPatchManager::executeBatchFile() chmod(batchFilename.c_str(), S_IRWXU); #endif - std::string cmdLine = "\"" + batchFilename + "\" " + LoginLogin + " " + LoginPassword; + std::string arguments = LoginLogin + " " + LoginPassword; if (!r2Mode) { - cmdLine += " " + toString(LoginShardId); + arguments += " " + toString(LoginShardId); } - if (launchProgram("", cmdLine, false)) + if (launchProgram(batchFilename, arguments, false)) { exit(0); }