Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

PathEnvironment with CreateProcess()

Posted on 1998-09-15
19
Medium Priority
?
259 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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
 
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 400 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

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…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

650 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