frank@odetics.com (Frank Merrow) (10/02/90)
Hi All, I wanted to create a MS-DOS environment variable at boot time off the form set TODAY=yymmdd so that other *.BAT files can create backup files and other such things. I looked threw the MS-C manual and found putevn() and getenv(), but they seem to effect the PROGRAM's copy of the environment, while I want to effect "THE" environment. Anyone got a good/easy way to do this? Frank P.S. If not "easy" then there must be a pointer to the DOS enviroment someplace, where is it and how does the structure look?
kdq@demott.COM (Kevin D. Quitt) (10/03/90)
In article <1990Oct1.191910.560@odetics.com> frank@odetics.com (Frank Merrow) writes: > >I wanted to create a MS-DOS environment variable at boot time off the form >set TODAY=yymmdd so that other *.BAT files can create backup files and >other such things. I looked threw the MS-C manual and found putevn() and >getenv(), but they seem to effect the PROGRAM's copy of the environment, while >I want to effect "THE" environment. > >Anyone got a good/easy way to do this? An easy cheat that doesn't require the use of undocumented system calls is to write "set today=yymmdd" to a file called "today.bat". Have your autoexec invoke your settoday program, then the today batch file. (Make sure you CALL TODAY, and don't just invoke it directly, unless it's the last thing your autoexec.bat is going to do). -- _ Kevin D. Quitt demott!kdq kdq@demott.com DeMott Electronics Co. 14707 Keswick St. Van Nuys, CA 91405-1266 VOICE (818) 988-4975 FAX (818) 997-1190 MODEM (818) 997-4496 PEP last 96.37% of all statistics are made up.
cgordon@vpnet.chi.il.us (Gordon Hlavenka) (10/04/90)
>... I looked threw the MS-C manual and found putevn() and >getenv(), but they seem to effect the PROGRAM's copy of the environment, >while >I want to effect "THE" environment. > >Anyone got a good/easy way to do this? Microsoft distributed (with source!) a program called WHAT.EXE with at least some copies of MASM 5.0. This program makes changes in the master environment, and since the source is available you should be able to patch it around. I got my copy from a BBS somewhere, but I'm not sure of the legality of its distribution. There doesn't seem to be _any_ copyright notice, which I think is suspicious. You might want to dig up a copy of MASM 5.0 and hope... >P.S. If not "easy" then there must be a pointer to the DOS enviroment >someplace, >where is it and how does the structure look? I don't know of any pointer; I've found it using DEBUG by just S'ing from low RAM upwards, for the first occurence of the string 'COMSPEC='. It shouldn't be too tough to write something that does that. Poking this table from within DEBUG is effective. Poking from within a program will _not_ affect that program's environment; it's working from a copy of the old environment. Next program loaded by DOS should get it, though. Of course, I don't know how reliable this method is... (For instance, I don't think it's guaranteed that the environment will start with 'COMSPEC='. That's just been my experience.) The structure: Simply a list of ASCIIZ strings, terminated by a null string (00H 00H). Actually, it is a list of strings followed by n bytes of zero, where n is the remaining "reserved" environment space (minimum 2 bytes). Real-world example: (Pardon me while I shell out) Deep Thought C>debug -s1000:0lffff 'COMSPEC=' 1000:A050 1000:A110 1000:A730 1000:C1A0 1000:D010 1000:DE30 1000:DF60 -d1000:a050lb0 1000:A050 43 4F 4D 53 50 45 43 3D-43 3A 5C 43 4F 4D 4D 41 COMSPEC=C:\COMMA 1000:A060 4E 44 2E 43 4F 4D 00 50-52 4F 4D 50 54 3D 44 65 ND.COM.PROMPT=De 1000:A070 65 70 20 54 68 6F 75 67-68 74 20 24 4E 24 47 00 ep Thought $N$G. 1000:A080 50 41 54 48 3D 43 3A 5C-3B 43 3A 5C 42 41 54 43 PATH=C:\;C:\BATC 1000:A090 48 3B 43 3A 5C 44 4F 53-3B 43 3A 5C 55 54 49 4C H;C:\DOS;C:\UTIL 1000:A0A0 3B 43 3A 5C 4E 4F 52 54-4F 4E 3B 43 3A 5C 47 41 ;C:\NORTON;C:\GA 1000:A0B0 4D 45 53 3B 43 3A 5C 54-4F 50 53 3B 45 3A 5C 57 MES;C:\TOPS;E:\W 1000:A0C0 49 4E 33 30 00 55 53 45-52 3D 47 6F 72 64 6F 6E IN30.USER=Gordon 1000:A0D0 00 54 45 4D 50 3D 65 3A-5C 00 4D 45 4D 4F 5F 44 .TEMP=e:\.MEMO_D 1000:A0E0 49 52 3D 63 3A 5C 6D 65-6D 6F 00 4D 45 4D 4F 5F IR=c:\memo.MEMO_ 1000:A0F0 46 49 4C 45 3D 6D 65 6D-6F 00 00 00 00 00 00 00 FILE=memo....... -q Good luck, and enjoy! ----------------------------------------------------- Gordon S. Hlavenka cgordon@vpnet.chi.il.us Disclaimer: Yeah, I said it. So what?