[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Using SETENVIRONMENTVARIABLE to pass value to calling CMD-file

Posted on 1997-08-01
13
Medium Priority
?
299 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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
 
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 300 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

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

656 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