Solved

PathEnvironment with CreateProcess()

Posted on 1998-09-15
19
251 Views
Last Modified: 2010-04-02
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
Comment
Question by:juerg
  • 7
  • 6
  • 4
  • +1
19 Comments
 

Author Comment

by:juerg
ID: 1172724
Edited text of question
0
 
LVL 22

Expert Comment

by:nietod
ID: 1172725
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
 

Author Comment

by:juerg
ID: 1172726
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
 
LVL 22

Expert Comment

by:nietod
ID: 1172727
What happens if you try to run the exe at the command line (from a directory that doesn't contain EXE?)
0
 

Author Comment

by:juerg
ID: 1172728
The ExeFile is winZip32.exe and it runs from each directory.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1172729
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
 
LVL 10

Expert Comment

by:viktornet
ID: 1172730
Sorry I forgot the \\ in the files name C:\\windows\\notepad
0
 
LVL 22

Expert Comment

by:nietod
ID: 1172731
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
 
LVL 10

Expert Comment

by:viktornet
ID: 1172732
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 10

Expert Comment

by:viktornet
ID: 1172733
It works in Delphi, why not in VC++????

Regards,
Viktor Ivanov
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1172734
Also if the WinZip.exe isn;t in the system dircetory you need to specify exact path to the executable...
//Vik
0
 

Author Comment

by:juerg
ID: 1172735
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
 
LVL 11

Expert Comment

by:alexo
ID: 1172736
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
 
LVL 22

Expert Comment

by:nietod
ID: 1172737
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
 
LVL 11

Expert Comment

by:alexo
ID: 1172738
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
 
LVL 10

Expert Comment

by:viktornet
ID: 1172739
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
 

Author Comment

by:juerg
ID: 1172740
!! 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
 
LVL 10

Accepted Solution

by:
viktornet earned 100 total points
ID: 1172741
Hello Juerg!

Thanks a lot!

Just accept this answer ;-)

Regards,
Viktor Ivanov
0
 

Author Comment

by:juerg
ID: 1172742
Thanks a lot

Juerg
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now