• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 263
  • Last Modified:

PathEnvironment with CreateProcess()

Hello

I start an ExeFile with CreateProcess(...).
It works fine when the exeFile is in the same directory.
Then I move the exeFile in another directory,
set the path environment to this directory too
and start my program.

Now the returnValue from CreateProcess(...) is zero
The ErrorCode from GetLastError() is 2 (-> file not found)

In the description from CreateProcess(..) is written ..
-
-If the filename does not contain a directory path, the system searches for the executable file in the following
-sequence:
-
-1. The .....
-2. .......
-6. The directories that are listed in the PATH environment variable.
-
? Why doesn't my application search in the PATH environment?
? Do I have to set any Parameters ?

below is a part from the sourceCode :


PROCESS_INFORMATION procInfo;
STARTUPINFO startupInfo = {0};
startupInfo.cb = sizeof(STARTUPINFO);
char attr[] = "winzip32.exe -min -a test.zip test.txt";
char process[] = "winzip32.exe";

// start the ScriptFile
m_create  = CreateProcess(process, attr,NULL, NULL, FALSE, 0, NULL, NULL, &startupInfo, &procInfo);
if (m_create == 0) {
 m_error = GetLastError();
}

Thanks for your answer
  Juerg
0
juerg
Asked:
juerg
  • 7
  • 6
  • 4
  • +1
1 Solution
 
juergAuthor Commented:
Edited text of question
0
 
nietodCommented:
Does the EXE use DLLs that were in the same directory?  If so, move them as well.
When/how did you change the path?  the new path might not be being used.  If you alter the path in your autoexec and then reboot that would be best.
0
 
juergAuthor Commented:
Platform is WindowsNT
Path is Set a long time before, because ExeFile is WinZip32.exe -> installed since one year.
DLLs are in the same directory then ExeFile
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
nietodCommented:
What happens if you try to run the exe at the command line (from a directory that doesn't contain EXE?)
0
 
juergAuthor Commented:
The ExeFile is winZip32.exe and it runs from each directory.
0
 
viktornetCommented:
Try this...

{
  STARTUPINFO si;
  PROCESS_INFORMATION pi;
  si.cb = sizeof(si);
  CreateProcess(NULL,"C:\windows\notepad",NULL,NULL,FALSE,0,NULL,NULL,&si,&pi);
}

Regards,
Viktor Ivanov
0
 
viktornetCommented:
Sorry I forgot the \\ in the files name C:\\windows\\notepad
0
 
nietodCommented:
viktornet, have you read the question?  what does you answer have to do with this?

juerg, I don't seen anything wrong in what you are doing.  You might want to play with things and see what happens.  for example, what happens if you use CreateProcess, but specify a path to the EXE, does it find it then?  What hapens if you don't specify the .exe?  what happens if you specify the exe in the 2nd parameter (the program parameter string) instead of the first? etc.
0
 
viktornetCommented:
My example shows an example without using the .exe on the path and also has a NULL as the first parameter of the CreateProcess() procedure ...

If he tries the way I gave him, he might succed, but it's not a promise just a guess....Try the code and then if it doesn't work , reject my answer.... ThanQ

Regards,
Viktor Ivanov
0
 
viktornetCommented:
It works in Delphi, why not in VC++????

Regards,
Viktor Ivanov
0
 
viktornetCommented:
Also if the WinZip.exe isn;t in the system dircetory you need to specify exact path to the executable...
//Vik
0
 
juergAuthor Commented:
Id'like to have the winZip32.exe everywhere on the machine (they are customersMachines)
Id'like to have my programm everywhere.

So Excuse me, but your answers did'nt help me.

What I have to do now is searching by my self in all directories from the PathEnvironment
for I file named "winZip32.exe" and than call createProcess(..) with the full path of my winZip32.exe

Sorry but no points

   Juerg
0
 
alexoCommented:
The docs say:  If lpApplicationName is NULL, the first white space-delimited token of the command line specifies the module name.  [...]  If the filename does not contain a directory path, Windows searches for the executable file in the following sequence: [...]

Therefore, try:

m_create = CreateProcess(NULL, attr, NULL, NULL, FALSE, 0, NULL, NULL, &startupInfo, &procInfo);

And if it works, give the points to Viktor.

0
 
nietodCommented:
Alex is right.  The information about the search path applies only to the second parameter.  Not to both the first and second.  I missed that.
0
 
alexoCommented:
It's about time I'm right about something (after making a total fool of myself challenging a solution submitted by no other than Ozo...)
0
 
viktornetCommented:
Hello! When you install WinZip(is it's the original one) it creates a ShortCut in the System directory so it is supose to be working....

BTW Thanks Alexo :-)

Regards,
Viktor Ivanov
0
 
juergAuthor Commented:
!! Thats it !!
Thanks a lot to all of you !
My fault was this damn.... first attribut

but now I have another question

? Please tell me how I can give the 100 Points to Viktor ?

Regards
 Juerg

0
 
viktornetCommented:
Hello Juerg!

Thanks a lot!

Just accept this answer ;-)

Regards,
Viktor Ivanov
0
 
juergAuthor Commented:
Thanks a lot

Juerg
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 7
  • 6
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now