Solved

Using SETENVIRONMENTVARIABLE to pass value to calling CMD-file

Posted on 1997-08-01
13
290 Views
Last Modified: 2013-11-18
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



0
Comment
Question by:miauw
  • 6
  • 5
  • 2
13 Comments
 

Author Comment

by:miauw
ID: 1340323
Edited text of question
0
 
LVL 1

Expert Comment

by:peter_vc
ID: 1340324
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
 
LVL 1

Expert Comment

by:peter_vc
ID: 1340325
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
 

Author Comment

by:miauw
ID: 1340326
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
 

Author Comment

by:miauw
ID: 1340327
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
 
LVL 3

Expert Comment

by:mirek071497
ID: 1340328
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 3

Expert Comment

by:mirek071497
ID: 1340329
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
 

Author Comment

by:miauw
ID: 1340330
I know and I knew.
0
 
LVL 3

Expert Comment

by:mirek071497
ID: 1340331
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
 

Author Comment

by:miauw
ID: 1340332
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
 
LVL 3

Expert Comment

by:mirek071497
ID: 1340333
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
 

Author Comment

by:miauw
ID: 1340334
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
 
LVL 3

Accepted Solution

by:
mirek071497 earned 100 total points
ID: 1340335
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

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
The viewer will learn how to count occurrences of each item in an array.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now