Using SETENVIRONMENTVARIABLE to pass value to calling CMD-file

I want to set a (NT 4.0 cmd) dos-environmentvariable depending on userinput of my delphi 2.0 program.
The batchfile will look something like this:
----TEST.CMD--------
SET VarToSet=NIL
DELPHIPROGRAM.EXE
CALL BLA.CMD %VarToSet%
-----------------------------
I succeed in setting and getting the needed values within
my delphiprogram by using SET/GETENVIRONMENTVARIABLE
but in the CMD-file the value always remains NIL.

Could you please giving a working example of setting
 the dosvariable VarToSet to This_Works such that
the batchfile will read it.

Thanx,
 Jeroen



miauwAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

miauwAuthor Commented:
Edited text of question
0
peter_vcCommented:
SET/GETENVIRONMENTVARIABLE deal with the current environment.
When you execute your Delphi program, isn't a new environment created for it, and therefore not accessible where you need it to be?  If you open two DOS boxes, and set a variable in one, can you see it in the other?  I don't have NT installed so I can't check.  Under Windows95, each DOS box gets it own copy of the environment, so any changes are only local.



0
peter_vcCommented:
After having a look in the MSWindows section, I see a pending answer for a similar problem where using the registry seem to be the answer.

0
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

miauwAuthor Commented:
Environmental variables can be global (e.g. when defined at boot)
or local. Yes: in two dos boxes creating a new variable will
not make this variable visible in the other dos box.

The point is that in a sense executing the delphi program from
within a cmdfile as mentioned above is kind a like a daugther
process to the cmdfile. So the  delphi program can read variables
from the motherprocess (those set in the batchfile).
The delphi program can not however SET those variables because
those settings are local to the daughter (at least I do not
know how/which tric is needed).

I thought about using the registry (or a temporary file), but I must be able to have several (copies of the same) cmdfiles running at the same time on the same computer. So: this complicates using the registry (too? much extra administration is needed).

Thanx for your comments, but I didn't answer my question.


0
miauwAuthor Commented:
Environmental variables can be global (e.g. when defined at boot)
or local. Yes: in two dos boxes creating a new variable will
not make this variable visible in the other dos box.

The point is that in a sense executing the delphi program from
within a cmdfile as mentioned above is kind a like a daugther
process to the cmdfile. So the  delphi program can read variables
from the motherprocess (those set in the batchfile).
The delphi program can not however SET those variables because
those settings are local to the daughter (at least I do not
know how/which tric is needed).

I thought about using the registry (or a temporary file), but I must be able to have several (copies of the same) cmdfiles running at the same time on the same computer. So: this complicates using the registry (too? much extra administration is needed).

Thanx for your comments, but I didn't answer my question.


0
mirek071497Commented:
Sorry you can't do this.

You can make changes in registry but this apply when you relogging. If You don't need relogging you can send WM_WININICHANGE to progman

var  
  s : array[0..40] of char;
  p : pChar;
begin
  StrPCopy( s, 'Progman' );
  p := 'Environment';
  Windows.SendMessage( FindWindow( s,nil ), WM_WININICHANGE, 0, Longint( p ) );
end;

but changes apply to all new command prompts not for current.

You can't change environment for another process.
0
mirek071497Commented:
User environment variables can be modified using the System control panel
application or by editing the following Registry key:

   HKEY_CURRENT_USER \
         Environment

System environment variables can be modified using the System control panel application or by editing the following
Registry key:

   HKEY_LOCAL_MACHINE \
               SYSTEM \
    CurrentControlSet \
              Control \
      Session Manager \
          Environment


0
miauwAuthor Commented:
I know and I knew.
0
mirek071497Commented:
My english is poo so i can't understand you'r comment but you can't do this in any way. You can do this in Win95 but not in Win NT !
I submit this as comment but this is answer. You don't need wait for any other.
0
miauwAuthor Commented:
Other research too has made this clear to me. Send in a
answer containing nothing and I'll grant you your well deserved points.
0
mirek071497Commented:
Sorry. You are right. Next time i must write more why you can't so plase don't blame me and decrease points (for example 25) then i submit as an answer
0
miauwAuthor Commented:
This question is NOT OPEN. It is answered by MIREK. If he sends in his answer again I will grade it (because I do not
know how to accept his comment as a answer).
0
mirek071497Commented:
OK. this is answer.

but i find so you can do this in Windows NT !!!!!

>--from Microsoft SDK
"...In Windows NT, you can retrieve a handle to any process in the system by enabling the SeDebugPrivilege in the calling process. The calling process can then call the OpenProcess() Win32 API to obtain a handle with PROCESS_ALL_ACCESS.
..."

When You have acces to process then You can change everything. but this is dangerous and great complicated.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.