I remember write a script in 2009 that use mountvol for do the task, but i delete it for avoid problems for a possible damage using the script. I remember that was possible unmount c: even using that causes serious problems, forcing to reset.
First, you need get the volume name of what you need mount / unmount.
For example: If I run mountvol I get this:
Code: Select all
C:\>mountvol
Crea, suprime o lista un punto de montaje de volumen.
MOUNTVOL [unidad:]ruta Nombre_Volumen
MOUNTVOL [unidad:]ruta /D
MOUNTVOL [unidad:]ruta /L
ruta Especifica el directorio NTFS en el que se establecerá
el punto de montaje.
volumen Especifica el nombre de volumen que será el destino del
punto de montaje.
/D Quita el punto de montaje de volumen del directorio
especificado.
/L Lista el nombre de volumen montado para el directorio
especificado.
Los valores posibles para Nombre_Volumen junto con los actuales puntos de montaj
e son:
\\?\Volume{a9f1bd02-fb62-11e2-bbf5-806d6172696f}\
C:\
\\?\Volume{a9f1bd00-fb62-11e2-bbf5-806d6172696f}\
D:\
\\?\Volume{f31ca7ce-4ff2-11e3-b6fb-080027c713cc}\
G:\
I know that G:\ is a removable drive, then I will save the volume name of it:
Note: in this: If we save inside variable is better remove the backslashes and copy all from Volume to }
Code: Select all
Volume{f31ca7ce-4ff2-11e3-b6fb-080027c713cc}
code that unmount if it is mounted, and mount if it is unmounted.
note: use under your own responsability. I'm not responsable of possible damage or other problem.
Code: Select all
@echo off
set "volume=Volume{f31ca7ce-4ff2-11e3-b6fb-080027c713cc}"
set "drive="
set "unused="
for %%D in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
mountvol %%D: /L >nul
if errorlevel 1 (
rem set free letter
set "free=%%D"
) else (
rem set the letter that use the volume
mountvol %%D: /L | findstr "%volume%" >nul
if not errorlevel 1 set "drive=%%D"
)
)
if not defined drive (
echo the volume is not mounted
) else (
echo the volume is mounted in %drive%
)
::unmount
if defined drive (
echo unmounting
mountvol %drive%: /D
)
::mount
if not defined drive (
if not defined free (
echo is not possible mount the volume because there are not a letter free
) else (
echo mounting in %free%:
mountvol %free%:\ \\?\%volume%\
)
)
pause
I test in my pc, and works.