Article View: comp.os.msdos.programmer
Article #6071Re: How to change the prompt?
From: Trevor George Campbell CC361
Date: Mon, 06 May 1991 11:32
Date: Mon, 06 May 1991 11:32
57 lines
3277 bytes
3277 bytes
Kai.Buerhoop@arbi.informatik.uni-oldenburg.de (Kai Buerhoop) writes:
>How can I change the prompt-string from within a program?
>I tried, using turbo-c's getenv("PROMPT"), which returns a pointer
>to that place in the memory, where the prompt-string is stored
>(which is okay).
>But seemingly, DOS creates a copy of the environment table, and the
>getenv returns a pointer to the copied env-table.
>So, when the program ends, DOS gets its old env-table, and all changes
>were futile. :(=
Correct.....
Check out Interrupt 21h Function 4Ch (EXEC) and you will see what happens....
If you are using Dos 4, try the command 'mem /debug' this will display the
contents of memory (addresses, program names, length..etc) if you have several
(or even 1) TSR loaded then you will notice entries like...
address prog. name length ?????
xxxxx COMMAND xxxxx Environment
xxxxx COMMAND xxxxx Program
xxxxx MEM xxxxx Environment
xxxxx MEM xxxxx Program
from this you can see that mem (the program you just run) has it's own copy of
the environment), just as you suspected....
>So, how to change the original environment table?
with great difficulty......
you need to use an undocumented (i think) function to find the address of the
first MCB (Memory Control Block)... From this you chain through the list
(like a linked list) checking if the first 8 bytes of the memory location are
COMSPEC=... this will mean that you have an environment block. The REAL (ie:
the one DOS uses) will usually (? always) be the first. The MCB contains the
length of the block of memory. Given this you need to check the environment
block for two NULL bytes (ie: 00 00 hex) one after the other, if this is
encountered before the end of the block of memory, (ie: there is still
sufficient memory in the block) then you need to copy all of the environment
variables after PROMPT= out of the way, change PROMPT= to the new string, and
then copy all of the other variables back after PROMPT=.
It's NOT easy to do, however i understand that it CAN be done... It basically
is just like the problem of trying to return ANY environment variable to DOS..
If you are not detered by the difficulty of doing it then there is a good
book by ABACUS called PC SYSTEMS PROGRAMMING FOR DEVELOPERS, it gives the
source code (in C and Pascal) to display the Memory Control Blocks and what
they contain (ie: environment, program, data or unknown...)
Hope this Helps.....
Trevor alias <**<TOMCAT>**>
Technical Details
Message-ID:
<campbell.673529564@cutmcvax>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!samsung!uunet!munnari.oz.au!uniwa!cc.curtin.edu.au!cutmcvax!campbellReferences:
<galad.673033210@aragorn>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!samsung!uunet!munnari.oz.au!uniwa!cc.curtin.edu.au!cutmcvax!campbell From: campbell@cutmcvax.cs.curtin.edu.au (Trevor George Campbell CC361) Newsgroups: comp.os.msdos.programmer Subject: Re: How to change the prompt? Keywords: prompt environment variables Message-ID: <campbell.673529564@cutmcvax> Date: 6 May 91 11:32:44 GMT References: <galad.673033210@aragorn> Sender: news@cutmcvax.cs.curtin.edu.au (Usenet News System) Organization: Curtin University of Technology, Computing Science Lines: 57 Nntp-Posting-Host: cutmcvax.cs.curtin.edu.au