How to assign a drive letter to a volume by name (not driveumber)?

  • Thread starter Thread starter Michael
  • Start date Start date
M

Michael

Hello

I know how to assign a drive letter to a volume with diskpart.

But diskpart has the disadvantage that you have to name the volume by its
volumenumber. And the volumenumber may change so the script gives the wrong
drive the letter.

Is there a way or scripting tool to assign a drive (volume) a drive letter
by selecting the name of the drive?

Thank you very much for help!

MIchael
 
-----Original Message-----
From: Michael [mailto:[email protected]]
Posted At: Thursday, October 19, 2006 1:13 PM
Posted To: microsoft.public.win2000.cmdprompt.admin
Conversation: How to assign a drive letter to a volume by name (not
driveumber)?
Subject: How to assign a drive letter to a volume by name (not
driveumber)?

Hello

I know how to assign a drive letter to a volume with diskpart.

But diskpart has the disadvantage that you have to name the volume by
its
volumenumber. And the volumenumber may change so the script gives
the wrong
drive the letter.

Is there a way or scripting tool to assign a drive (volume) a drive letter
by selecting the name of the drive?

Thank you very much for help!

MIchael

Michael,

By "name of the drive", do you mean volume label? If yes, you can first
run diskpart /s script.txt with "list volume" command inside script.txt
and parse output of the command to find volume number based on known
volume label. There's two caveats however. Note however that diskpart
shows only first 11 characters of volume label.

If you need a batch example, let me know.
 
Hello Alexander
thanks for your answer. That sounds a good solution. I would appreciate very
much if you send me an example
ciao
MIChael

Alexander Suhovey said:
-----Original Message-----
From: Michael [mailto:[email protected]]
Posted At: Thursday, October 19, 2006 1:13 PM
Posted To: microsoft.public.win2000.cmdprompt.admin
Conversation: How to assign a drive letter to a volume by name (not
driveumber)?
Subject: How to assign a drive letter to a volume by name (not
driveumber)?

Hello

I know how to assign a drive letter to a volume with diskpart.

But diskpart has the disadvantage that you have to name the volume by
its
volumenumber. And the volumenumber may change so the script gives
the wrong
drive the letter.

Is there a way or scripting tool to assign a drive (volume) a drive letter
by selecting the name of the drive?

Thank you very much for help!

MIchael

Michael,

By "name of the drive", do you mean volume label? If yes, you can first
run diskpart /s script.txt with "list volume" command inside script.txt
and parse output of the command to find volume number based on known
volume label. There's two caveats however. Note however that diskpart
shows only first 11 characters of volume label.

If you need a batch example, let me know.
 
-----Original Message-----
From: Michael [mailto:[email protected]]
Posted At: Thursday, October 19, 2006 6:21 PM
Posted To: microsoft.public.win2000.cmdprompt.admin
Conversation: How to assign a drive letter to a volume by name (not
driveumber)?
Subject: Re: How to assign a drive letter to a volume by name (not
driveumber)?

Hello Alexander
thanks for your answer. That sounds a good solution. I would appreciate
very
much if you send me an example
ciao
MIChael

Alexander Suhovey said:
-----Original Message-----
From: Michael [mailto:[email protected]]
Posted At: Thursday, October 19, 2006 1:13 PM
Posted To: microsoft.public.win2000.cmdprompt.admin
Conversation: How to assign a drive letter to a volume by name (not
driveumber)?
Subject: How to assign a drive letter to a volume by name (not
driveumber)?

Hello

I know how to assign a drive letter to a volume with diskpart.

But diskpart has the disadvantage that you have to name the volume by
its
volumenumber. And the volumenumber may change so the script gives
the wrong
drive the letter.

Is there a way or scripting tool to assign a drive (volume) a drive letter
by selecting the name of the drive?

Thank you very much for help!

MIchael

Michael,

By "name of the drive", do you mean volume label? If yes, you can first
run diskpart /s script.txt with "list volume" command inside script.txt
and parse output of the command to find volume number based on known
volume label. There's two caveats however. Note however that diskpart
shows only first 11 characters of volume label.

If you need a batch example, let me know.

Here we go:
======start batch script=======
@echo off
setlocal ENABLEDELAYEDEXPANSION
:: Full path to diskpart.exe. Defaults are:
:: Windows 2000: "C:\Program Files\Resource Kit\diskpart.exe"
:: 2003/XP: "C:\windows\system32\diskpart.exe"
set dp=c:\windows\system32\diskpart.exe

:: Volume label
set label=MY_VOLUME_LABEL

:: Temporary command file for diskpart.exe
set dps="%TEMP%\dp.txt"

echo list volume>%dps%
echo exit>>%dps%
set label_short=%LABEL:~0,11%
if exist %dp% (
for /f "delims=" %%i in ('%dp% /s %dps%') do (
set string=%%i
if not "!string:%label_short%=!"=="!string!" (
set volnum=!string:~9,3!
set volnum=!volnum: =!
)
)
if not "!volnum!"=="" (
echo Volume Label: %label%
echo Volume Number: !volnum!
) else (
echo Cannot find volume with label %label%
)
) else (
echo Cannot find %dp%&goto :EOF
)
=======end batch script========
 
-----Original Message-----
From: Alexander Suhovey [mailto:[email protected]]
Posted At: Friday, October 20, 2006 7:18 PM
Posted To: microsoft.public.win2000.cmdprompt.admin
Conversation: How to assign a drive letter to a volume by name (not
driveumber)?
Subject: Re: How to assign a drive letter to a volume by name (not
driveumber)?
-----Original Message-----
From: Michael [mailto:[email protected]]
Posted At: Thursday, October 19, 2006 6:21 PM
Posted To: microsoft.public.win2000.cmdprompt.admin
Conversation: How to assign a drive letter to a volume by name (not
driveumber)?
Subject: Re: How to assign a drive letter to a volume by name (not
driveumber)?

Hello Alexander
thanks for your answer. That sounds a good solution. I would appreciate
very
much if you send me an example
ciao
MIChael

Alexander Suhovey said:
-----Original Message-----
From: Michael [mailto:[email protected]]
Posted At: Thursday, October 19, 2006 1:13 PM
Posted To: microsoft.public.win2000.cmdprompt.admin
Conversation: How to assign a drive letter to a volume by name (not
driveumber)?
Subject: How to assign a drive letter to a volume by name (not
driveumber)?

Hello

I know how to assign a drive letter to a volume with diskpart.

But diskpart has the disadvantage that you have to name the
volume
by
its
volumenumber. And the volumenumber may change so the script gives
the wrong
drive the letter.

Is there a way or scripting tool to assign a drive (volume) a drive
letter
by selecting the name of the drive?

Thank you very much for help!

MIchael

Michael,

By "name of the drive", do you mean volume label? If yes, you can first
run diskpart /s script.txt with "list volume" command inside script.txt
and parse output of the command to find volume number based on known
volume label. There's two caveats however. Note however that diskpart
shows only first 11 characters of volume label.

If you need a batch example, let me know.

Here we go:
======start batch script=======
@echo off
setlocal ENABLEDELAYEDEXPANSION
:: Full path to diskpart.exe. Defaults are:
:: Windows 2000: "C:\Program Files\Resource Kit\diskpart.exe"
:: 2003/XP: "C:\windows\system32\diskpart.exe"
set dp=c:\windows\system32\diskpart.exe

:: Volume label
set label=MY_VOLUME_LABEL

:: Temporary command file for diskpart.exe
set dps="%TEMP%\dp.txt"

echo list volume>%dps%
echo exit>>%dps%
set label_short=%LABEL:~0,11%
if exist %dp% (
for /f "delims=" %%i in ('%dp% /s %dps%') do (
set string=%%i
if not "!string:%label_short%=!"=="!string!" (
set volnum=!string:~9,3!
set volnum=!volnum: =!
)
)
if not "!volnum!"=="" (
echo Volume Label: %label%
echo Volume Number: !volnum!
) else (
echo Cannot find volume with label %label%
)
) else (
echo Cannot find %dp%&goto :EOF
)
=======end batch script========

There's limitation however: If you have several volumes that have labels
with same first 11 characters, script will assgn number of last such
volume found to VOLNUM variable.
 
Hey you did it all!!!
Thank you very very much!!!!
your script works great and Im happy.
I tried it on my own but didnt manage it.
:-))))))))))
ciao
MIchael

Alexander Suhovey said:
-----Original Message-----
From: Michael [mailto:[email protected]]
Posted At: Thursday, October 19, 2006 6:21 PM
Posted To: microsoft.public.win2000.cmdprompt.admin
Conversation: How to assign a drive letter to a volume by name (not
driveumber)?
Subject: Re: How to assign a drive letter to a volume by name (not
driveumber)?

Hello Alexander
thanks for your answer. That sounds a good solution. I would appreciate
very
much if you send me an example
ciao
MIChael

Alexander Suhovey said:
-----Original Message-----
From: Michael [mailto:[email protected]]
Posted At: Thursday, October 19, 2006 1:13 PM
Posted To: microsoft.public.win2000.cmdprompt.admin
Conversation: How to assign a drive letter to a volume by name (not
driveumber)?
Subject: How to assign a drive letter to a volume by name (not
driveumber)?

Hello

I know how to assign a drive letter to a volume with diskpart.

But diskpart has the disadvantage that you have to name the volume by
its
volumenumber. And the volumenumber may change so the script gives
the wrong
drive the letter.

Is there a way or scripting tool to assign a drive (volume) a drive
letter
by selecting the name of the drive?

Thank you very much for help!

MIchael

Michael,

By "name of the drive", do you mean volume label? If yes, you can first
run diskpart /s script.txt with "list volume" command inside script.txt
and parse output of the command to find volume number based on known
volume label. There's two caveats however. Note however that diskpart
shows only first 11 characters of volume label.

If you need a batch example, let me know.

Here we go:
======start batch script=======
@echo off
setlocal ENABLEDELAYEDEXPANSION
:: Full path to diskpart.exe. Defaults are:
:: Windows 2000: "C:\Program Files\Resource Kit\diskpart.exe"
:: 2003/XP: "C:\windows\system32\diskpart.exe"
set dp=c:\windows\system32\diskpart.exe

:: Volume label
set label=MY_VOLUME_LABEL

:: Temporary command file for diskpart.exe
set dps="%TEMP%\dp.txt"

echo list volume>%dps%
echo exit>>%dps%
set label_short=%LABEL:~0,11%
if exist %dp% (
for /f "delims=" %%i in ('%dp% /s %dps%') do (
set string=%%i
if not "!string:%label_short%=!"=="!string!" (
set volnum=!string:~9,3!
set volnum=!volnum: =!
)
)
if not "!volnum!"=="" (
echo Volume Label: %label%
echo Volume Number: !volnum!
) else (
echo Cannot find volume with label %label%
)
) else (
echo Cannot find %dp%&goto :EOF
)
=======end batch script========
 
Michael said:
Hey you did it all!!!
Thank you very very much!!!!
your script works great and Im happy.
I tried it on my own but didnt manage it.
:-))))))))))
ciao
MIchael

You are welcome, Michael.
 
Back
Top