Posts

How to use %username% variable in vbscripts

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
on error resume next
Set WshNetwork = WScript.CreateObject(“WScript.Network”)
WshNetwork.RemoveNetworkDrive “U:”
WshNetwork.MapNetworkDrive “U:”, “mawfi-2008r2.mawfi.localusers$” & WshNetwork.UserName , True