Solved

PathEnvironment with CreateProcess()

Posted on 1998-09-15
19
250 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
Comment Utility
Edited text of question
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
The ExeFile is winZip32.exe and it runs from each directory.
0
 
LVL 10

Expert Comment

by:viktornet
Comment Utility
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
Comment Utility
Sorry I forgot the \\ in the files name C:\\windows\\notepad
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
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
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 10

Expert Comment

by:viktornet
Comment Utility
It works in Delphi, why not in VC++????

Regards,
Viktor Ivanov
0
 
LVL 10

Expert Comment

by:viktornet
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
!! 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
Comment Utility
Hello Juerg!

Thanks a lot!

Just accept this answer ;-)

Regards,
Viktor Ivanov
0
 

Author Comment

by:juerg
Comment Utility
Thanks a lot

Juerg
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

771 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

10 Experts available now in Live!

Get 1:1 Help Now