Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!cmcl2!rutgers!sunybcs!boulder!hao!oddjob!gargoyle!ihnp4!homxb!whuts!mtune!westmark!dave From: dave@westmark.UUCP (Dave Levenson) Newsgroups: comp.sys.ibm.pc Subject: Re: Environment settings from a C program Message-ID: <213@westmark.UUCP> Date: Tue, 13-Oct-87 22:32:42 EDT Article-I.D.: westmark.213 Posted: Tue Oct 13 22:32:42 1987 Date-Received: Thu, 15-Oct-87 23:53:41 EDT References: <700@hsi.UUCP> Organization: Westmark, Inc., Warren, NJ, USA Lines: 30 Keywords: ms-dos environ putenv getenv turboc In article <700@hsi.UUCP>, mark@hsi.UUCP (Mark Sicignano) writes: > I am trying to change an environment variable from within > a Turbo-C program. Turbo-C provides a function, putenv() > which will make changes to, add, or delete environment, > but any changes are made to the environment within the program, > and for child processes. In MS-DOS, as in UNIX, you can change your environment, and then export it to your children, but you cannot change your parent's environment. You inherit a copy, and operate on it. Unlike UNIX, however, MS-DOS cannot protect itself from applications that disobey its rules. If you can find out where your parent keeps its environment, you can alter it. The segment address of your environment block appears at offset 2C in your PSP. Offset 16 of your PSP contains the segment address of your parent's PSP. Offset 16 of your parent's PSP points at your grandparent's PSP, and so on. (The first PSP, belonging to COMMAND.COM, points to itself!) Offset 2C of your parent's PSP holds the segment address of your parent's environment block. You probably won't be able to get there with putenv() but with enough chaining through enough far pointers, you can probably accomplish what you want to. -- Dave Levenson Westmark, Inc. A node for news. Warren, NJ USA {rutgers | clyde | mtune | ihnp4}!westmark!dave