Solved

Using SETENVIRONMENTVARIABLE to pass value to calling CMD-file

Posted on 1997-08-01
13
291 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

912 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

24 Experts available now in Live!

Get 1:1 Help Now