Discussion:
CreateProcess problem
(too old to reply)
battles
2010-12-10 13:06:40 UTC
Permalink
I have the following CreateProcess that is not starting the program
successfully. The error is that the program that is started cannot
find a config file it needs to open. I have tried to point to
the .exe's folder in executableparameters as well as puting in the
whole file name, putting them in double quotes, but that doesn't work
either. Any ideas on how to get the CreateProcess to pass the ability
to find the files it needs? Thanks.

with lpStartupInfo do begin
FillChar(lpStartupInfo, SizeOf(lpStartupInfo), 0);
cb := SizeOf(lpStartupInfo);
dwFlags := STARTF_USESHOWWINDOW; //// or
STARTF_USESTDHANDLES;
wShowWindow := SW_HIDE;
hStdInput := GetStdHandle(STD_INPUT_HANDLE); // don't
redirect std input
end;

if FileExists(filenm) then begin
with lpStartupInfo2 do begin
FillChar(lpStartupInfo2, SizeOf(lpStartupInfo2),
0);
cb := SizeOf(lpStartupInfo2);
dwFlags := STARTF_USESHOWWINDOW; //// or
STARTF_USESTDHANDLES;
wShowWindow := SW_HIDE;
hStdInput := GetStdHandle(STD_INPUT_HANDLE); //
don't redirect std input
end;

CreateProcess(
PChar(trim(filenm)), // pointer to name of executable
module
PChar(executableparameters),// pointer to command
line string
nil, // pointer to process
security attributes
nil, // pointer to thread
security attributes
FALSE, // handle inheritance
flag
CREATE_NEW_PROCESS_GROUP OR NORMAL_PRIORITY_CLASS,
nil, // pointer to new
environment block
nil, // pointer to current
directory name
lpStartupInfo2, // pointer to
STARTUPINFO
lpProcessInformation2); // pointer to
PROCESS_INFORMATION

//bombs before OpenProcess

OpenProcess(
PROCESS_ALL_ACCESS, // access flag
TRUE, // handle inheritance
flag
lpProcessInformation2.hProcess); // process
identifier - PID

AHandleArray[AHA] :=
lpProcessInformation2.dwProcessId; // process identifier - PID
inc(AHA);
end
JJ
2010-12-10 23:59:58 UTC
Permalink
Post by battles
I have the following CreateProcess that is not starting the program
successfully. The error is that the program that is started cannot
find a config file it needs to open. I have tried to point to
the .exe's folder in executableparameters as well as puting in the
whole file name, putting them in double quotes, but that doesn't work
either. Any ideas on how to get the CreateProcess to pass the ability
to find the files it needs? Thanks.
[snip]

That's an error from the program you're trying to execute. The program
is probably trying to find its configuration file in current directory,
which may not the directory where the program is located. You should
specify the program's path to the CreateProcess.
battles
2010-12-11 15:43:33 UTC
Permalink
Post by JJ
Post by battles
I have the following CreateProcess that is not starting the program
successfully. The error is that the program that is started cannot
find a config file it needs to open. I have tried to point to
the .exe's folder in executableparameters as well as puting in the
whole file name, putting them in double quotes, but that doesn't work
either. Any ideas on how to get the CreateProcess to pass the ability
to find the files it needs? Thanks.
[snip]
That's an error from the program you're trying to execute. The program
is probably trying to find its configuration file in current directory,
which may not the directory where the program is located. You should
specify the program's path to the CreateProcess.
Yes, that is the problem. But I am passing the full path to the
executable in filenm, so I thought it would find it thru it. I also
tried passing the path to the file in '// pointer to current
directory name' and '// pointer to command line string'.
Ali Svensson
2010-12-11 16:26:21 UTC
Permalink
Post by battles
Yes, that is the problem. But I am passing the full path to the
executable in filenm, so I thought it would find it thru it.
For test, try putting your command on Windows Start -->Run command line.
You will see that you get the same error messages when the app is
started outside it's own working directory.

Try this, how to pass the Working Directory to your app:
http://delphi.about.com/od/windowsshellapi/a/executeprogram.htm
"StartInString specifies the
name of the working directory.
If ommited, the current directory is used.
}
// lpDirectory := PChar(StartInString) ;
nShow := SW_SHOWNORMAL;
end;"

That's only a snippet, I did not test anything. I have used ShellExecute
for years instead of this. Of course there is the same Working Dir
problem to overcome also. -as
battles
2010-12-11 18:55:40 UTC
Permalink
Post by Ali Svensson
Post by battles
Yes, that is the problem. But I am passing the full path to the
executable in filenm, so I thought it would find it thru it.
For test, try putting your command on Windows Start -->Run command line.
You will see that you get the same error messages when the app is
started outside it's own working directory.
http://delphi.about.com/od/windowsshellapi/a/executeprogram.htm
"StartInString specifies the
name of the working directory.
If ommited, the current directory is used.
}
// lpDirectory := PChar(StartInString) ;
nShow := SW_SHOWNORMAL;
end;"
That's only a snippet, I did not test anything. I have used ShellExecute
for years instead of this. Of course there is the same Working Dir
problem to overcome also. -as
That was where it belonged. I for the life of me don't know how I
couldn't see that down there.
Thanks!

Loading...