diff --git a/launcher/src/CmderLauncher.cpp b/launcher/src/CmderLauncher.cpp index 6ac22e5..510d8ad 100644 --- a/launcher/src/CmderLauncher.cpp +++ b/launcher/src/CmderLauncher.cpp @@ -3,6 +3,8 @@ #include #include "resource.h" #include +#include + #pragma comment(lib, "Shlwapi.lib") @@ -156,13 +158,18 @@ void StartCmder(std::wstring path, bool is_single_mode) SetEnvironmentVariable(L"CMDER_ROOT", exeDir); if (!streqi(path.c_str(), L"")) { - SetEnvironmentVariable(L"CMDER_START", path.c_str()); + if (!SetEnvironmentVariable(L"CMDER_START", path.c_str())) { + MessageBox(NULL, _T("Error trying to set CMDER_START to given path!"), _T("Error"), MB_OK); + } } else { - static wchar_t buff[MAX_PATH] = { 0 }; - GetEnvironmentVariable(L"USER_PROFILE", buff, MAX_PATH); - SetEnvironmentVariable(L"CMDER_START", buff); + wchar_t* homeProfile = 0; + SHGetKnownFolderPath(FOLDERID_Profile, 0, NULL, &homeProfile); + if (!SetEnvironmentVariable(L"CMDER_START", homeProfile)) { + MessageBox(NULL, _T("Error trying to set CMDER_START to USER_PROFILE!"), _T("Error"), MB_OK); + } + CoTaskMemFree(static_cast(homeProfile)); } // Ensure EnvironmentVariables are propagated. @@ -177,8 +184,10 @@ void StartCmder(std::wstring path, bool is_single_mode) #endif PROCESS_INFORMATION pi; - - CreateProcess(conEmuPath, args, NULL, NULL, false, 0, NULL, NULL, &si, &pi); + if (!CreateProcess(conEmuPath, args, NULL, NULL, false, 0, NULL, NULL, &si, &pi)) { + MessageBox(NULL, _T("Unable to create the ConEmu Process!"), _T("Error"), MB_OK); + return; + } } bool IsUserOnly(std::wstring opt)