views:

56

answers:

1

Hello,

I am running two processes,Process A is opened by Process B using the following example:

    createProcessHandle = CreateProcess(
TEXT("C:\\Users\Jamie\\Documents\\Application\\Debug\\ProcessA.exe"),
                    TEXT(""),
                    NULL,
                    NULL,
                    FALSE,
                    0,
                    NULL,
                    NULL,
                    &startupinfo,
                    &process_information
                    );

As you can see the Process is reliant on the path given to it, the problem I have is that if I change the location of my ProcessA.exe (Such as a backup/duplicate) it's a tiresome process to keep recoding the path. I want to be able to make it run no matter where it is without having to recode the path manually.

Can anybody suggest a solution to this?

Edit: I do not have access to the path environment variable

+2  A: 

There are basically two options.

  1. Use a relative path.
  2. Put the directory in your PATH environment variable. In this case, use lpCommandLine, not lpApplicationName.
Matthew Flaschen
Unfortunately I cannot do option 2, can you explain option 1 to me?
Jamie Keeling
See http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx . Basically, if ProcessA and ProcessB were in the same directory, you could just put ProcessA.exe. If ProcessA were in a sub-directory called subdir, you could put subidir/ProcessA.exe
Matthew Flaschen
Excellent, thanks!
Jamie Keeling