Coding in MS-DOS / Batch Files

Electronic Punk

Staff member
Political Access
2 Dec 2001
I am writing a batch file and have a problem with one of the sections

echo ; Section 4 - Default values for each service.>> custom11.PRF
echo ;***************************************************************>> custom11.PRF
echo.>> custom11.PRF
echo [ServiceX]>> custom11.PRF
echo CachedExchangeMode=0x00000003>> custom11.PRF
echo CachedExchangeSlowDetect=TRUE>> custom11.PRF
echo.>> custom11.PRF
echo [ServiceEGS]>> custom11.PRF
echo CachedExchangeConfigFlags=0x00000500>> custom11.PRF
echo MailboxName=%UserName%>> custom11.PRF
echo>> custom11.PRF

Basically echo MailboxName=%UserName%>> custom11.PRF would ideally output MailboxName=%UserName% into the file custom11.PRF but is instead using the global variable of the username which isn't so good as it will be running as a machine logon script, is there any way I can get around this?

Edited to remove company name.
Last edited:
EP, try using two %%
echo mailboxname=%%username%% >> custom11.prf
I'll give it a go tomorrow.
Actually resigned to the idea of being able to use a single batch file so now have a bat, reg/vbs and a prf file... Updating community server to 2007.1 at work now woo ;D
Why would the need be there to use two of the %%?
as EP mentioned, he wanted to write out the string as a literal string "mailbox=%username%". If you leave the one %, the batch file processing will take that to mean it is a variable and will substitute the variable when echo'ing the line. so, "mailbox=%username%" when he writes to the outlook.prf file becomes "mailbox=drose" or whatever the %username% variable is set to.

If this is running in a machine startup script, the username variable would probably not be defined yet (or running under system) which means the line gets written out as "mailbox=" in the prf file which will obviously cause problems when said user wants to start outlook to create a mailbox.

Even if it was writing out the proper username, a further issue arises when someone else uses the machine since the prf file would try to build a profile for the other user. Setting it to the global variable %username% in the prf file would allow anyone to sit at the computer, start outlook, and build the correct profile.

Using the two %% is the escape character so the batch file will see the string as a literal string "%username%" instead of a variable.
fitz > derek and the red sox.

all hail the fitz
Both Derek and the Yankees will prevail this season!
Sorry to drag this back on topic.

H:\>echo %%USERNAME%%
that would be correct if you did that on the command line, however, write it in a short batch file to write out to a file and it will show up correctly.
@echo off
echo %%username%%
c:\> test.bat

Members online

No members online now.

Latest profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.

Forum statistics

Latest member