@echo off

if [%~1]==[] (
    goto usage
) else (
    set "drive_letter=%~1"
)
if not [%~2]==[] set "user=%~2"


:execute
set "basedirname=virtual_drives"
set "basepath=%systemdrive%\%basedirname%"
if not exist %basepath% (
    md %basepath%
)
if [%user%]==[] (
    net use %drive_letter%: "\\%COMPUTERNAME%\virtual_drives\%drive_letter%" /persistent:yes
) else (
    net use %drive_letter%: "\\%COMPUTERNAME%\virtual_drives\%drive_letter%" /user:"%USERDOMAIN%\%user%" /persistent:yes
)
goto cleanup


:usage
@echo Usage: %0 driveletter [username]
exit /b 1


:cleanup
