If your script requires a mapped drive, you would normally use tip 1002 » Using a temporary drive letter is a batch.

If the client doesn't have any available drive letters, or your script expects a specific drive letter, which may be improperly mapped, you can use remap.bat to determine the current mapping of the drive letter you want to use. The syntax is:

remap <DriveLetter>

Remap.bat returns the drive environment variable set to the <DriveLetter> parameter you used, if the <DriveLetter> is mapped. If the <DriveLetter> is mapped, it also returns the map environment variable with the current mapping.

Remap.bat contains:

@echo off                              setlocal                              If "%1" EQU "" goto syntax                              set param=%1                              for /f "Skip=6 Tokens=*" %%i in ('net use') do set line="%%i"&call :parse                              endlocal&set drive=%drive%&set map=%map%                              goto :EOF                              :syntax                              @echo Syntax: remap DriveLetter                              endlocal                              goto :EOF                              :parse                              If /i NOT "%line:~14,1%" EQU "%param%" goto :EOF                              set drive=%line:~14,1%                              set map=%line:~24,99%                              set map=%map:Microsoft Windows Network"=%#                              :loop                              set wrk=%map%                              set wrk=%wrk: #=#%                              if "%wrk%" EQU "%map%" goto final                              set map=%wrk%                              goto :loop                              :final                              set map=%map:#=%

If you want to use drive letter m to run your script:

@echo off                              remap m                              if /i NOT "%drive%" EQU "m" goto yourM                              net use M: /delete                              :yourM                              net use M: \\YourServer\YourShare                              YourScript.bat                              net use M: /delete                              if /i NOT "%drive%" EQU "m" goto :EOF                              net use M: %map% /persistent:YES