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

Batch file set permissions based on foldername %username%

@echo off
set zLog=ResetHomePerms.log
cls
echo FIXHOME.BAT
echo This script will reset permissions for all subdirectories
echo in this folder.  It is assumed that the subdirectories
echo are named the same as their respective username.
echo.
choice /C YN /M “Are you sure you want to proceed?”
if errorlevel 2 GOTO :Exit
if errorlevel 1 GOTO :MAIN
:MAIN
if exist %zLog% del %zlog% >NUL
choice /C CF /M “Do you want users to have (C)hange or (F)ull control permissions?”
if errorlevel 2 GOTO ResetF
if errorlevel 1 GOTO ResetC
:RESETF
echo Granting users FULL permissions
echo.
echo Granting users FULL permissions >>%zlog%
for /f %%i in (‘dir /b /ad’) do @echo %%i >>%zLog% && echo y|cacls %%i /T /g Administrators:F >NUL && cacls %%i /T /e /g %userdomain%%%i:F >>%zLog% && echo **********>>%Zlog%
REM rem out or modify the following line if you do not want to give Domain Admins Full control
for /f %%i in (‘dir /b /ad’) do @echo %%i >>%zLog% && cacls %%i /T /e /g “%userdomain%Domain Admins”:F >>%zLog% && echo **********>>%Zlog%
goto :CLOSE
:RESETC
echo Granting users CHANGE permissions
echo.
echo Granting users CHANGE permissions >>%zlog%
for /f %%i in (‘dir /b /ad’) do @echo %%i >>%zLog% && echo y|cacls %%i /T /g Administrators:F >NUL && cacls %%i /T /e /g %userdomain%%%i:C >>%zLog% && echo **********>>%Zlog%
REM rem out or modify the following line if you do not want to give Domain Admins Full control
for /f %%i in (‘dir /b /ad’) do @echo %%i >>%zLog% && cacls %%i /T /e /g “%userdomain%Domain Admins”:F >>%zLog% && echo **********>>%Zlog%
goto :CLOSE
:CLOSE
echo. >>%zLog%
date /t >>%zlog% && time /t >>%zLog%
echo.
echo See %zlog% for details
set zLog=
set zLogError=
:EXIT
echo Exiting script

Script to remove all network shares

Option Explicit
Dim objNetwork, objShell, strDriveLetter, strDriveLetter2, strDriveLetter3, strDriveLetter4, strDriveLetter5, strDriveLetter6, strDriveLetter7, strDriveLetter8, strDriveLetter9, strDriveLetter10, strDriveLetter11, strDriveLetter12, strDriveLetter13, strDriveLetter14, strDriveLetter15, strDriveLetter16, strDriveLetter17, strDriveLetter18, strDriveLetter19, strDriveLetter20, strDriveLetter21, strDriveLetter22, strDriveLetter23, strDriveLetter24, strDriveLetter25
Dim bForce, bUpdateProfile
strDriveLetter = “e:”
strDriveLetter2 = “d:”
strDriveLetter3 = “e:”
strDriveLetter4 = “f:”
strDriveLetter5 = “g:”
strDriveLetter6 = “h:”
strDriveLetter7 = “i:”
strDriveLetter8 = “j:”
strDriveLetter9 = “k:”
strDriveLetter10 = “l:”
strDriveLetter11 = “m:”
strDriveLetter13 = “n:”
strDriveLetter14 = “o:”
strDriveLetter15 = “p:”
strDriveLetter16 = “q:”
strDriveLetter17 = “r:”
strDriveLetter18 = “s:”
strDriveLetter19 = “t:”
strDriveLetter20 = “u:”
strDriveLetter21 = “v:”
strDriveLetter22 = “w:”
strDriveLetter23 = “x:”
strDriveLetter24 = “y:”
strDriveLetter25 = “z:”
bForce = “True”
bUpdateProfile = “True”
err.number = vbempty
Set objNetwork = CreateObject(“WScript.Network”)
‘ Removes strDriveLetter, with bForce, pUpdate Profile
On Error Resume Next
objNetwork.RemoveNetworkDrive strDriveLetter, bforce, bUpdateProfile
objNetwork.RemoveNetworkDrive strDriveLetter2, bforce, bUpdateProfile
objNetwork.RemoveNetworkDrive strDriveLetter3, bforce, bUpdateProfile
objNetwork.RemoveNetworkDrive strDriveLetter4, bforce, bUpdateProfile
objNetwork.RemoveNetworkDrive strDriveLetter5, bforce, bUpdateProfile
objNetwork.RemoveNetworkDrive strDriveLetter6, bforce, bUpdateProfile
objNetwork.RemoveNetworkDrive strDriveLetter7, bforce, bUpdateProfile
objNetwork.RemoveNetworkDrive strDriveLetter8, bforce, bUpdateProfile
objNetwork.RemoveNetworkDrive strDriveLetter9, bforce, bUpdateProfile
objNetwork.RemoveNetworkDrive strDriveLetter10, bforce, bUpdateProfile
objNetwork.RemoveNetworkDrive strDriveLetter11, bforce, bUpdateProfile
objNetwork.RemoveNetworkDrive strDriveLetter12, bforce, bUpdateProfile
objNetwork.RemoveNetworkDrive strDriveLetter13, bforce, bUpdateProfile
objNetwork.RemoveNetworkDrive strDriveLetter14, bforce, bUpdateProfile
objNetwork.RemoveNetworkDrive strDriveLetter15, bforce, bUpdateProfile
objNetwork.RemoveNetworkDrive strDriveLetter16, bforce, bUpdateProfile
objNetwork.RemoveNetworkDrive strDriveLetter17, bforce, bUpdateProfile
objNetwork.RemoveNetworkDrive strDriveLetter18, bforce, bUpdateProfile
objNetwork.RemoveNetworkDrive strDriveLetter19, bforce, bUpdateProfile
objNetwork.RemoveNetworkDrive strDriveLetter20, bforce, bUpdateProfile
objNetwork.RemoveNetworkDrive strDriveLetter21, bforce, bUpdateProfile
objNetwork.RemoveNetworkDrive strDriveLetter22, bforce, bUpdateProfile
objNetwork.RemoveNetworkDrive strDriveLetter23, bforce, bUpdateProfile
objNetwork.RemoveNetworkDrive strDriveLetter24, bforce, bUpdateProfile
objNetwork.RemoveNetworkDrive strDriveLetter25, bforce, bUpdateProfile
‘ Error correcting code
If err.number = vbEmpty then
Set objShell = CreateObject(“WScript.Shell”)
objShell.run (“Explorer”)
End If