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

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
 
A

Alexander Suhovey

-----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.
 
M

Michael

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.
 
A

Alexander Suhovey

-----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========
 
A

Alexander Suhovey

-----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.
 
M

Michael

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========
 
A

Alexander Suhovey

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top