delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/08/16/08:00:46

From: Hans-Bernhard Broeker <broeker AT physik DOT rwth-aachen DOT de>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Need help to set master enviroment
Date: 16 Aug 2000 11:57:37 GMT
Organization: Aachen University of Technology (RWTH)
Lines: 38
Message-ID: <8ndvjh$i75$1@nets3.rz.RWTH-Aachen.DE>
References: <8n9alo$858$1 AT nnrp1 DOT deja DOT com>
NNTP-Posting-Host: acp3bf.physik.rwth-aachen.de
X-Trace: nets3.rz.RWTH-Aachen.DE 966427057 18661 137.226.32.75 (16 Aug 2000 11:57:37 GMT)
X-Complaints-To: abuse AT rwth-aachen DOT de
NNTP-Posting-Date: 16 Aug 2000 11:57:37 GMT
Originator: broeker@
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

rui_paz AT my-deja DOT com wrote:
> Hi,

> Can sameone point me to info about making a program using DJGPP that can
> change the master enviroment to set a variable?

You're not supposed to be allowed doing such a thing, originally.  The
master environment belongs to its owner (the root command.com), which
is supposed to be protected from other processes mingling with its
data structures. I.e. you shouldn't be doing that, usually.

That said: there *are* ways to do it. (There always are, on an OS as
badly protected against malicious software as DOS). 

Two ways are well-known:

1) Use undocumented DOS methods to walk the chain of memory blocks 
   and find the one that stores the environment block for the master
   copy of command.com. This is essentially the same thing 'mem /d'
   does. You'll need at lowlevel system docs like Ralf Brown's Interrupt 
   List to be able to do that. Using DJGPP to do it will complicate 
   matters further.

2) Call your own C program from a .bat file, let it write another,
   temporary .bat file, and have the first batch execute the second,
   after termination of the C application:

	@echo off
	c:\some\where\yourprog.exe
	if exist %TEMP%\yourprog.bat call %TEMP%\yourprog.bat
	if exist %TEMP%\yourprog.bat del %TEMP%\yourprog.bat

   In this setup, yourprog.exe can output 'set var=content' lines into
   %TEMP%\yourprog.bat, and they'll be executed, and change the
   master environment, after termination of yourprog.exe.
-- 
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019