Coding in MS-DOS / Batch Files

Discussion in 'Web Design & Coding' started by Electronic Punk, Sep 19, 2007.

  1. Electronic Punk

    Electronic Punk Administrator Staff Member Political User Folding Team

    Messages:
    18,590
    Location:
    Copenhagen, Denmark
    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: Sep 19, 2007
  2. fitz

    fitz Just Floating Along Staff Member Political User Folding Team

    Messages:
    4,076
    Location:
    Chicagoland
    EP, try using two %%
    Code:
    echo mailboxname=%%username%% >> custom11.prf
    
     
  3. Electronic Punk

    Electronic Punk Administrator Staff Member Political User Folding Team

    Messages:
    18,590
    Location:
    Copenhagen, Denmark
    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
     
  4. kcnychief

    kcnychief █▄█ ▀█▄ █ Political User Folding Team

    Messages:
    16,948
    Location:
    Massachusetts
    Why would the need be there to use two of the %%?
     
  5. fitz

    fitz Just Floating Along Staff Member Political User Folding Team

    Messages:
    4,076
    Location:
    Chicagoland
    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.
     
    kcnychief likes this.
  6. kcnychief

    kcnychief █▄█ ▀█▄ █ Political User Folding Team

    Messages:
    16,948
    Location:
    Massachusetts
    Nice explanation, thanks.
     
  7. Sazar

    Sazar F@H - Is it in you? Staff Member Political User Folding Team

    Messages:
    14,905
    Location:
    Between Austin and Tampa
    fitz > derek and the red sox.

    all hail the fitz
     
  8. fitz

    fitz Just Floating Along Staff Member Political User Folding Team

    Messages:
    4,076
    Location:
    Chicagoland
    *cough* *cough* that's right,.. love me!

    :p
     
  9. kcnychief

    kcnychief █▄█ ▀█▄ █ Political User Folding Team

    Messages:
    16,948
    Location:
    Massachusetts
    Both Derek and the Yankees will prevail this season!
     
  10. Electronic Punk

    Electronic Punk Administrator Staff Member Political User Folding Team

    Messages:
    18,590
    Location:
    Copenhagen, Denmark
    Sorry to drag this back on topic.

    H:\>echo %%USERNAME%%
    %husbandp%
     
  11. fitz

    fitz Just Floating Along Staff Member Political User Folding Team

    Messages:
    4,076
    Location:
    Chicagoland
    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%%
    
     
  12. fitz

    fitz Just Floating Along Staff Member Political User Folding Team

    Messages:
    4,076
    Location:
    Chicagoland
    get this sorted out yet EP?