• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Coding in MS-DOS / Batch Files

Electronic Punk

willalwaysbewithyou
Staff member
Political User
#1
I am writing a batch file and have a problem with one of the sections

Code:
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 HomeServer=mail.network.local>> 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:

Electronic Punk

willalwaysbewithyou
Staff member
Political User
#3
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
 

fitz

Woah.. I'm still here?
Staff member
Political User
#5
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

Woah.. I'm still here?
Staff member
Political User
#11
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.
Code:
@echo off
echo %%username%%
c:\> test.bat
%username%
 

Members online

No members online now.

Latest posts

Latest profile posts

Hello, is there anybody in there? Just nod if you can hear me ...
Xie
What a long strange trip it's been. =)

Forum statistics

Threads
61,961
Messages
673,239
Members
89,014
Latest member
sanoravies