Velocity Technical Archive
How to use %username% variable in vbscripts
Archived Reference: This is a historical technical article preserved from the Velocity Technologies knowledge base. For current Phoenix and East Valley managed IT services, explore our managed IT services or cybersecurity solutions.
If you try to use a vbscript to map a network drive using the %username% variable it will not work. The reason for this is the %username% variable only works in .bat files. The equivelant in vbscript is objNetwork.UserName That being said here is an example\non error resume next\nSet WshNetwork = WScript.CreateObject("WScript.Network")\nWshNetwork.RemoveNetworkDrive "U:"\nWshNetwork.MapNetworkDrive "U:", "mawfi-2008r2.mawfi.localusers$" & WshNetwork.UserName , True\n