@@ -179,31 +179,40 @@ int main(int argc, char* argv[]) {
179179 }
180180
181181 if (rich_requested) {
182- char exePath[ MAX_PATH ];
183- GetModuleFileNameA ( NULL , exePath, MAX_PATH ) ;
182+ char env_buf[ 4 ];
183+ bool already_spawned = GetEnvironmentVariableA ( " VMAWARE_RICH_SPAWN " , env_buf, sizeof (env_buf)) > 0 ;
184184
185- char currentDir[MAX_PATH ];
186- GetCurrentDirectoryA (MAX_PATH , currentDir);
185+ if (!already_spawned) {
186+ char exePath[MAX_PATH ];
187+ GetModuleFileNameA (NULL , exePath, MAX_PATH );
187188
188- std::string args = " \" " + std::string (exePath) + " \" " ;
189- for (int i = 1 ; i < argc; ++i) {
190- args += " \" " ;
191- args += argv[i];
192- args += " \" " ;
193- }
189+ char currentDir[MAX_PATH ];
190+ GetCurrentDirectoryA (MAX_PATH , currentDir);
191+
192+ std::string args = " \" " + std::string (exePath) + " \" " ;
193+ for (int i = 1 ; i < argc; ++i) {
194+ args += " \" " ;
195+ args += argv[i];
196+ args += " \" " ;
197+ }
198+
199+ SHELLEXECUTEINFOA sei = { sizeof (sei) };
200+ sei.fMask = 0 ;
201+ sei.hwnd = NULL ;
202+ sei.lpVerb = " open" ;
203+ sei.lpFile = " conhost.exe" ;
204+ sei.lpParameters = args.c_str ();
205+ sei.lpDirectory = currentDir;
206+ sei.nShow = SW_SHOWNORMAL ;
194207
195- SHELLEXECUTEINFOA sei = { sizeof (sei) };
196- sei.fMask = 0 ;
197- sei.hwnd = NULL ;
198- sei.lpVerb = " open" ;
199- sei.lpFile = " conhost.exe" ;
200- sei.lpParameters = args.c_str ();
201- sei.lpDirectory = currentDir;
202- sei.nShow = SW_SHOWNORMAL ;
203-
204- if (!IsDebuggerPresent () && ShellExecuteExA (&sei)) {
205- ExitProcess (0 );
206- }
208+ SetEnvironmentVariableA (" VMAWARE_RICH_SPAWN" , " 1" );
209+
210+ if (!IsDebuggerPresent () && ShellExecuteExA (&sei)) {
211+ ExitProcess (0 );
212+ }
213+
214+ SetEnvironmentVariableA (" VMAWARE_RICH_SPAWN" , nullptr );
215+ }
207216 }
208217
209218 win_ansi_enabler_t ansi_enabler;
0 commit comments