There are times you need to assign a temporary drive letter in a batch file, and delete it when you are done.

Here is fragment of such a script: (Note: %1 in this fragment is a UNC path parameter)

for /f "Tokens=*" %%i in ('net use * %1') do call :what "%%i"
if not defined drv goto error
REM Do whatever
@echo %drv%
net use %drv% /delete
goto end
set tst=%1
if not "%tst:~8,1%"<h1><a name="_goto_end_set_drv_tst_7_2_end_b_pre_Another_solution_is_to_use_b_PUSHD_b_and_b_POPD_b_pre_b_for_f_Tokens_i_in_CD_do_set_old_i_pushd_1_for_f_Tokens_i_in_CD_do_set_drv_i_if_old_">":" goto end
set drv=%tst:~7,2%
Another solution is to use PUSHD and POPD:
for /f "Tokens=*" %%i in ('CD') do set old=%%i
pushd %1
for /f "Tokens=*" %%i in ('CD') do set drv=%%i
if "%old%""%drv%" goto error
REM Do whatever
@echo %drv%