@echo off

if "%~1"=="" goto usage
goto main

:usage
@echo Usage: %0 ^<drive letter^> [^<drive letter^>]...
exit /b 1

:main
set basedirname=virtual_drives
set basepath=%systemdrive%\%basedirname%
if not exist %basepath% (
  md %basepath%
)
ver | find "5.1" && goto win_xp

:win_7
echo ":win_7"
icacls %basepath% /l /grant users:(oi)(ci)f
net share %basedirname%=%basepath% /grant:users,FULL
goto map_network_drives

:win_xp
echo ":win_xp"
cacls %basepath% /e /g users:f
net share %basedirname%=%basepath% /unlimited
goto map_network_drives

:map_network_drives
echo ":map_network_drives"

setlocal enabledelayedexpansion
set argCount=0
for %%x in (%*) do (
   set /A argCount+=1
   set "drive_letters[!argCount!]=%%~x"
)
for /L %%i in (1,1,%argCount%) do (
  if not exist %basepath%\"!drive_letters[%%i]!" (
    md %basepath%\!drive_letters[%%i]!
  )
  net use !drive_letters[%%i]!: \\%computername%\virtual_drives\!drive_letters[%%i]! /persistent:yes
)
