Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!texbell!texsun!letni!sneaky!merch!spudge!thorp From: thorp@spudge.UUCP (Don Thorp) Newsgroups: comp.sys.ibm.pc Subject: Re: MS-DOS Environment Variables Message-ID: <6551@spudge.UUCP> Date: 21 Nov 89 15:27:22 GMT References: <5679@wpi.wpi.edu> <1989Nov20.212803.5326@uwasa.fi> Reply-To: thorp@spudge.UUCP (Don Thorp) Organization: Friends of Guru Bob Lines: 88 The following code will set an environment variable in the highest environment. I compiled it with tasm and zortech cpp. But there should be no changes required for MSC or TurboC. The transient portion of command.com will be loaded. If there is not enough memory to load command.com, your system will crash. That is one of the side effects of using interrupt 2Eh. Don Thorp USENET ...!texbell!letni!rwsys!spudge!thorp <------------------------------Cut Here-----------------------------------> /********************************************************************** * setenv.h * **********************************************************************/ #if !defined(__SETENV_H__) #define __SETENV_H__ #if defined(__cplusplus) extern "C" { #endif void int2e(char *cmd); void setenv(const char *p); #if defined(__cplusplus) } #endif #endif <------------------------------Cut Here-----------------------------------> /************************************************************************* * setenv.c - Set the root environment * ************************************************************************/ #include #include #include "setenv.h" void setenv(const char *p) { char *cmd = malloc(strlen(p) + 3); cmd[0]=strlen(p); strcpy(cmd+1,p); strcat(cmd+1,"\r"); int2e(cmd); free(cmd); } <------------------------------Cut Here-----------------------------------> ; Interrupt 2Eh Call for C int2e.asm ; ; void _int2e(char *cmd) ; Public _int2e _TEXT Segment Byte Public 'CODE' Assume CS:_TEXT Stack dw ?,? _INT2E proc near push bp mov bp,sp push si ;Save registers push di push ds mov cs:[Stack], sp ;Save the stack pointer mov cs:[Stack+2], ss mov si, ss:[bp+4] ;Get parameter int 2eh ;do interrupt mov ss, cs:[Stack + 2] ;restore stack mov sp, cs:[Stack] pop ds pop di pop si pop bp ret _INT2E endp _TEXT ends end