Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

CreateProcess: environment block

241 views
Skip to first unread message

Torbjörn Johansson

unread,
Jun 20, 2001, 8:55:48 AM6/20/01
to
I've a problem with a service that starts another application. The problem
is that this app uses external dlls that uses enviroment variables and when
I start the app from the service it can't read them. I tried running the
service as sytem and admin but none works. Running the app normally works
fine.

I read in the help that you can set an enviroment block with createprocess,
and my question is how? A code example would be nice.

Regards
Torbjörn Johansson


Michael Winter

unread,
Jun 20, 2001, 4:21:05 PM6/20/01
to
"Torbjörn Johansson" schrieb:

> I read in the help that you can set an enviroment block with createprocess,
> and my question is how? A code example would be nice.

CreateProcess has a parameter called lpEnvironment. If you provide nil
there, the created process inherits the parent's environment. To run the
child process with another environment, provide a PChar pointing to
something like

'PATH=C:\Bla;C:\Blo'#0'TEMP=C:\winnt\temp'#0#0

To create such a pointer from a TStrings,use something like

function ZeroSeparatedList(L: TStrings): PChar;
begin
Result := PChar(StringReplace(L.Text, #13#10, #0, [rfReplaceAll]));
end;

Note that the child process creates a copy of the provided environment,
so it's fine to use simply

CreateProcess(..., ZeroSeparatedList(ChildEnv), ...

without any need to alloc or free additional buffers.

-Michael

Marcel van Brakel

unread,
Jun 20, 2001, 4:23:03 PM6/20/01
to
> CreateProcess has a parameter called lpEnvironment. If you provide nil
> there, the created process inherits the parent's environment. To run the
> child process with another environment, provide a PChar pointing to
> something like

In addition you can also use the CreateEnvironmentBlock API to get the
environment for a specific user...

best regards,
Marcel van Brakel

Project JEDI: http://delphi-jedi.org

Do not send me private e-mail unless explicitly requested otherwise.
If you do anyway please include a billing address...

Torbjörn Johansson

unread,
Jun 21, 2001, 5:24:15 AM6/21/01
to
Thank you so much and sorry for replying directly to your mail. Wrong button
: )

Torbjörn J


"Michael Winter" <delph...@gmx.net> wrote in message
news:3b31066b_1@dnews...

Torbjörn Johansson

unread,
Jun 21, 2001, 5:22:42 AM6/21/01
to
Great. Thank you so much.

Torbjörn J

"Marcel van Brakel" <brakelm...@chello.nl> wrote in message
news:MPG.159b24923...@newsgroups.borland.com...

Michael Winter

unread,
Jun 21, 2001, 3:44:05 PM6/21/01
to
Marcel van Brakel schrieb:

> In addition you can also use the CreateEnvironmentBlock API to get the
> environment for a specific user...

It's not in the API OH, and I'm too lazy to open MSDN. Is it a W2K
specific call? However, thank you for the hint.

-Michael


Marcel van Brakel

unread,
Jun 21, 2001, 5:07:01 PM6/21/01
to
> > In addition you can also use the CreateEnvironmentBlock API to get the
> > environment for a specific user...
>
> It's not in the API OH, and I'm too lazy to open MSDN. Is it a W2K
> specific call? However, thank you for the hint.

NT 4 up. You can find a declaration in the WinUser.pas file from my
win32api library at http://delphi-jedi.org

0 new messages