juerg
asked on
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
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
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.
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.
ASKER
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
Path is Set a long time before, because ExeFile is WinZip32.exe -> installed since one year.
DLLs are in the same directory then ExeFile
What happens if you try to run the exe at the command line (from a directory that doesn't contain EXE?)
ASKER
The ExeFile is winZip32.exe and it runs from each directory.
Try this...
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
si.cb = sizeof(si);
CreateProcess(NULL,"C:\win dows\notep ad",NULL,N ULL,FALSE, 0,NULL,NUL L,&si,&pi) ;
}
Regards,
Viktor Ivanov
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
si.cb = sizeof(si);
CreateProcess(NULL,"C:\win
}
Regards,
Viktor Ivanov
Sorry I forgot the \\ in the files name C:\\windows\\notepad
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.
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.
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
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
It works in Delphi, why not in VC++????
Regards,
Viktor Ivanov
Regards,
Viktor Ivanov
Also if the WinZip.exe isn;t in the system dircetory you need to specify exact path to the executable...
//Vik
//Vik
ASKER
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
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
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.
Therefore, try:
m_create = CreateProcess(NULL, attr, NULL, NULL, FALSE, 0, NULL, NULL, &startupInfo, &procInfo);
And if it works, give the points to Viktor.
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.
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...)
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
BTW Thanks Alexo :-)
Regards,
Viktor Ivanov
ASKER
!! 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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks a lot
Juerg
Juerg
ASKER