3
3
#include < Shlwapi.h>
4
4
#include " resource.h"
5
5
#include < vector>
6
+ #include < Shlobj.h>
7
+
6
8
7
9
#pragma comment(lib, "Shlwapi.lib")
8
10
@@ -153,17 +155,26 @@ void StartCmder(std::wstring path, bool is_single_mode)
153
155
swprintf_s (args, L" /Icon \" %s\" /Title Cmder" , icoPath);
154
156
}
155
157
156
- SetEnvironmentVariable (L" CMDER_ROOT" , exeDir);
157
- if (!streqi (path.c_str (), L" " ))
158
- {
159
- SetEnvironmentVariable (L" CMDER_START" , path.c_str ());
158
+ SetEnvironmentVariable (L" CMDER_ROOT" , exeDir);
159
+ if (!streqi (path.c_str (), L" " ))
160
+ {
161
+ if (!SetEnvironmentVariable (L" CMDER_START" , path.c_str ())) {
162
+ MessageBox (NULL , _T (" Error trying to set CMDER_START to given path!" ), _T (" Error" ), MB_OK);
160
163
}
161
-
162
- // Send out the Settings Changed message - Once using ANSII...
163
- // SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)"Environment", SMTO_ABORTIFHUNG, 5000, NULL);
164
-
165
- // ...and once using UniCode (because Windows 8 likes it that way).
166
- // SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM) L"Environment", SMTO_ABORTIFHUNG, 5000, NULL);
164
+ }
165
+ else
166
+ {
167
+ wchar_t * homeProfile = 0 ;
168
+ SHGetKnownFolderPath (FOLDERID_Profile, 0 , NULL , &homeProfile);
169
+ if (!SetEnvironmentVariable (L" CMDER_START" , homeProfile)) {
170
+ MessageBox (NULL , _T (" Error trying to set CMDER_START to USER_PROFILE!" ), _T (" Error" ), MB_OK);
171
+ }
172
+ CoTaskMemFree (static_cast <void *>(homeProfile));
173
+ }
174
+
175
+ // Ensure EnvironmentVariables are propagated.
176
+ SendMessageTimeout (HWND_BROADCAST, WM_SETTINGCHANGE, 0 , (LPARAM)" Environment" , SMTO_ABORTIFHUNG, 5000 , NULL );
177
+ SendMessageTimeout (HWND_BROADCAST, WM_SETTINGCHANGE, 0 , (LPARAM) L" Environment" , SMTO_ABORTIFHUNG, 5000 , NULL ); // For Windows >= 8
167
178
168
179
STARTUPINFO si = { 0 };
169
180
si.cb = sizeof (STARTUPINFO);
@@ -173,8 +184,10 @@ void StartCmder(std::wstring path, bool is_single_mode)
173
184
#endif
174
185
175
186
PROCESS_INFORMATION pi ;
176
-
177
- CreateProcess (conEmuPath, args, NULL , NULL , false , 0 , NULL , NULL , &si, &pi );
187
+ if (!CreateProcess (conEmuPath, args, NULL , NULL , false , 0 , NULL , NULL , &si, &pi )) {
188
+ MessageBox (NULL , _T (" Unable to create the ConEmu Process!" ), _T (" Error" ), MB_OK);
189
+ return ;
190
+ }
178
191
}
179
192
180
193
bool IsUserOnly (std::wstring opt)
0 commit comments