Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!julius.cs.uiuc.edu!rpi!uupsi!sunic!ugle.unit.no!ugle!thoger From: thoger@solan.unit.no (Terje Th|gersen) Newsgroups: comp.lang.pascal Subject: Re: Change ENV. Message-ID: Date: 14 Jan 91 22:59:32 GMT References: <25474@adm.brl.mil> <1991Jan14.143941.10541@javelin.es.com> Sender: news@ugle.unit.no Organization: The Norwegian Institute of Technology Lines: 85 In-Reply-To: bgeer@javelin.es.com's message of 14 Jan 91 14:39:41 GMT In article <1991Jan14.143941.10541@javelin.es.com> bgeer@javelin.es.com (Bob Geer) writes: ZCCBJSB%EB0UB011.BITNET@cunyvm.cuny.edu ( Info-Pascal list) writes: >Has anyone some code/idea to modify PERMANENTLY a DOS environtment >variable from a TP program (any TP version)? Each program run gets a new copy of the environment of the current program. For example, any changes to the environment of, say, a batch program doesn't make its way to the previous copy so is lost when the batch program terminates. Those changes only propogate to programs run from the batch file, or programs they subsequently run. Dr. Dobb's Journal #122 (December 1986) contained an article about MS-DOS' undocumented interrupt 2Eh which will change the `master' copy of the environment but not any copies already propogated from it. Below I've included a procedure fragment that I use to edit the path string. .......[deletions].... ---------------------------------------- -- <> Bob `Bear' Geer <> bgeer@javelin.sim.es.com <> <> Alta-holic <> speaking only for myself, one of my many tricks <> <> Salt Lake City, <> "We must strive to be more than we are, Lal." <> <> Ootah <> -- Cmdr. Data, learning schmaltz <> There's a problem with the Int2Eh approach, though. According to some refences, the use of INt2e will abort an executing batchfile. Also, a program that used Int2eh (which was posted here recently) bombed under QEMM 5.11, giving a exception #13.. A safer approach, as used by Microsoft in their WHAT.EXE, (a freebie that came with masm 5.0) is as follows : 1) read the word at [PREFIXSEG:$16]. This is the segment adress of the PSP of the parent of the current program. Read the word at that segment:$16, which will be the previous program in the chain. Repeat this until you find a PSP in which the word at $16 points to its own PSP. This will be 'granddaddy', the Master DOS environment. The word at PSP:$2c tells you where this master environment starts. This a series of ASCIIZ (#0-terminated strings) that ends in #0#0. Now, 'all you have to do' (:-)) is to smack your environment variables in here, byte for byte.. I have a program that actually does this (TP 5.5 code), but I think it's a bit rough yet to go public with. (I only got it working last saturday :-)) If you insert extra bytes into the env. area, you must be sure that you don't go out of the max number allocated to the environment. There's a word in the PSP somewhere that gives you the size of the environment area in 16-byte paragraphs, but I just can't remember which. (I don't have the code here, I'm afraid..) I think i found it in one of the public domain dos tech. ref. documents. Now, having found the env. area, and knowing the max size of it, you'll have to count up how much of it is in use. If the variable you're using is not in the environment already, all you have to do is add it at the end of the existing env., taking care to overwrite *one* of the two #0's that marks the end, and remembering to add two #0's after your string. If the variable is already in there I guess you could take different approaches, what I do is to copy the entire environment into a string array, delete 'my' variable, and add the new value to the end, before writing the whole array back. ( make sure you remember to exclude the length-byte at STRING[0]..) That's it, I think.. Hope this is understandable to those interested... I'll polish up my code and post it here, but as I've got my diploma thesis due very shortly now, it might take some time.. (if anyone wants rough code with (very few) *norwegian* language comments, mail me :-)) Bye, -Terje -- ____________________________________________________________________________ thoger@solan.unit.no | Institute of Physical Chemistry THOGER AT NORUNIT.BITNET | Div. of Computer Assisted Instrumental Analysis | Norwegian Institute of Technology