I have found this to work and added the shutdown and restart explorer to reflect drive changes.
I cannot get it tweaked to allow search by drive letter instead of drive description.
My reason for needing to change drive letter is due to the spreadsheets inside the flash media need locked onto a specific locked directory where user error is much lower.
This is a small part of a larger batch file which checks the current drive for correct letter assignment before allowing access to the folders inside.
:Change_Letter
cls
@echo ON
setlocal
echo Type The Name Of The Drive NOT The Letter!
set /p Label=
set Drive=W
set Confirm=1
set Volume=
set VolumesFile=%Temp%\Volumes.txt
set DiskPartFile=%Temp%\DiskPart.txt
echo Retrieving volume information ...
echo list volume | diskpart.exe | more +5 | find /v "DISKPART>" >"%VolumesFile%"
for /f "tokens=2" %%a in ('type "%VolumesFile%" ^| find /i "%Label%"') do (set Volume=%%a)
if "%Volume%"=="" (
echo No volume with the label '%Label%' found; existing volumes:
type "%VolumesFile%"
goto Leave
)
>%DiskPartFile% echo select volume %Volume%
>>%DiskPartFile% echo assign letter %Drive%
>>%DiskPartFile% echo exit
if "%Confirm%" equ "0" goto AssignLetter
echo.
echo The following volumes were found:
type "%VolumesFile%"
echo 'Volume %Volume%' will be assigned the drive letter '%Drive%'.
echo The following diskpart script will be executed:
type "%DiskPartFile%"
echo.
set Response=N
set /p "Response=Continue [y/N]? "
if /i not "%Response%"=="Y" (
echo Operation canceled.
goto Leave
)
:AssignLetter
echo Setting drive letter '%Drive%' for volume %Volume% ...
diskpart.exe /s "%DiskPartFile%"
echo Done.
:Leave
cls
CD\
Timeout /T 5
taskkill /f /im explorer.exe
Timeout /T 3
cls
CD\
start explorer.exe
if exist "%VolumesFile%" del "%VolumesFile%"
if exist "%DiskPartFile%" del "%DiskPartFile%"
Label W: LoganHayLLC
Timeout /T 4
Start W:\FileAccess.bat
exit