Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!bu-cs!acm From: acm@bu-cs.BU.EDU (ACM) Newsgroups: comp.sys.ibm.pc Subject: Re: Environment settings from a C program Message-ID: <14256@bu-cs.BU.EDU> Date: Mon, 12-Oct-87 20:02:55 EDT Article-I.D.: bu-cs.14256 Posted: Mon Oct 12 20:02:55 1987 Date-Received: Wed, 14-Oct-87 01:10:34 EDT References: <700@hsi.UUCP> <114@fxgrp.UUCP> <2168@ihlpe.ATT.COM> Reply-To: madd@bucsb.bu.edu Followup-To: madd@bucsb.bu.edu Organization: Boston University ACM Lines: 40 Keywords: ms-dos environ putenv getenv turboc In article <2168@ihlpe.ATT.COM> psfales@ihlpe.ATT.COM (Pete Fales) writes: >In article <114@fxgrp.UUCP>, ljz@fxgrp.UUCP (Lloyd Zusman) writes: >> 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. >> > >> >I need for these changes to remain. Is it possible? >> >> >> Sorry, but what you want to do isn't possible. DOS (be it MSDOS or PCDOS) > ^^^^^^^^^^^^^^ >> is written such that no running program can change the environment of its >> parent. In case you need more explanation, consider this: >> > >This is rather strong language for an operating system with no memory >protection. True. The way you do it is look for the pointer to the parent's PSP in your PSP. I forget the actual address of the pointer -- anyone out there know what it is? Anyway, after you find the parent's PSP you can get a pointer to the parent's environment and play with it as you like. it's not a bright idea to expand the environment because this is likely to cause massive memory problems. Expansion of the environment MUST NOT exceed the last paragraph in the environment (or the max size of the parent's environment -- in the case of COMMAND.COM you have some idea of what this will be). Normally you just setblock the environment pointer, but I don't think you can do this if you're playing with a parent process. Another point is that it's easy to backtrace through all the programs currently in memory with the pointer to the parent's PSP. I've seen some programs out there that do it -- nice to see what kind of stuff you've got stuck in memory. jim frost madd@bucsb.bu.edu