variable %username% not working RRS feed

  • Question

  • I'm not sure if it's just one of those weeks, but the variable %username% is not working.

    Here is what i'm trying to do:

    1. check if there is a folder named "tmp" under the user profile, if not create one

    i'm using:

    IF NOT EXIST %USERPROFILE%\tmp mkdir %USERPROFILE%\tmp   <<<<inside a .bat file

    this part works currently.

    2. Map a local folder "c:\users\%username%\tmp" to drive letter L.

    doesn't sound scary right? anybody point me in the right direction?

    here is what i'm stuck on:

    when i type %username% in the run box nothing happens, %userprofile% actually works, but it refers to c:\users\username, when used across the network such as \\servername\users$\%userprofile%, it ends up like \\servername\users$\c:\users\username and doesn't work. now i don't need it to go across the network, but when in combination with "net use" I imagine it has to resolve back to the host and then find the folder.

    Also, I have nothing against some way to map a drive letter to "%userprofile%\tmp" but net use won't do it.

    and when i do it through Subst, it shows up as a local drive, not a network drive, i would like for it to look like a network drive to not cause confusion.

    I might just be rambling on now.. help?


    • Edited by IT-Simón Friday, November 9, 2012 10:03 PM dotting i's and crossing Ts
    Friday, November 9, 2012 9:55 PM


  • Since these are console commands you should run them from a console, not from the Run box:

    echo %UserName%
    echo %UserProfile%
    net user  Q: "\\%ComputerName%\%UserName%"
    (I don't actually see the wisdom of running this command . . .)

    • Marked as answer by Cloud_TS Tuesday, December 4, 2012 7:04 AM
    Friday, November 9, 2012 10:12 PM