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?
 
mirek071497Connect With a Mentor Commented:
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
 
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
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.