renaming an exe while executing

newstandard
newstandard used Ask the Experts™
on
i asked this question a couple days ago

http://www.experts-exchange.com/Programming/Programming_Languages/MFC/Q_20720592.html

i wanted to execute an external exe and wait for its completion before my program continues

i used this code:

DWORD ExecuteAndWaitForCompletion   (   LPSTR   pszCmd)
{
  STARTUPINFO         si;
  PROCESS_INFORMATION pi;

  BOOL                bRes;

  DWORD               dwCode  =   0;

  MSG                 msg;

  ZeroMemory  (   &si,    sizeof  (   STARTUPINFO));

  si.cb           =   sizeof  (   STARTUPINFO);
  si.dwFlags      =   STARTF_USESHOWWINDOW;
  si.wShowWindow  =   SW_SHOWNORMAL;

  bRes    =   CreateProcess   (   NULL,
                                  pszCmd,
                                  NULL,
                                  NULL,
                                  TRUE,
                                  NORMAL_PRIORITY_CLASS,
                                  NULL,
                                  NULL,
                                  &si,
                                  &pi
                              );

  while   (   WAIT_OBJECT_0   !=  MsgWaitForMultipleObjects   (   1,
                                                                  &pi.hProcess,
                                                                  FALSE,
                                                                  INFINITE,
                                                                  QS_ALLINPUT
                                                              )
          )
          {
              while   (   PeekMessage (   &msg,   NULL,   0,  0,  PM_REMOVE))
                      {
                          DispatchMessage     (   &msg);
                      }
          }

  GetExitCodeProcess  (   pi.hProcess,    &dwCode);

  CloseHandle (   pi.hProcess);
  CloseHandle (   pi.hThread);

  return  (   dwCode);
}

it works just fine.  however, in another version of this same program (where I used .NET - which is why I'm redoing in MFC) i was able to launch the external EXE and then rename the EXE file to .tmp so the user would have a hard time finding it

i don't want the user to find this exe because it is an unencrypted thing that I don't want them to detach from my wrapper application

how can i modify the above code to rename the EXE to FILENAME.tmp after the EXE begins executing?

thanks,

Justin Kohlhepp
New Standard
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2012
Commented:
>>how can i modify the above code to rename the EXE to FILENAME.tmp after the EXE begins executing?

That's not possible. But, why don't you rename it to 'filename.tmp' *before* you execute it?

Author

Commented:
wow - yr good

Author

Commented:
btw i was able to rename it after execution started by using WaitForInputIdle(pi.hProcess,5000); and then doing the rename afterwords.  this makes sure that the process is fully loaded (or seemed to).

however, your way is much better because it is much less likely to cause problems

thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial