3.6. Setting the Label of a Volume

Problem

You want to set the label of a volume.

Solution

Using a graphical user interface

  1. Open Windows Explorer.

  2. Right-click the drive you want to clean up and select Properties.

  3. Click the General tab if it isn't opened by default.

  4. The lone input box on this tab is the label for the volume. Modify it as necessary and click OK.

Using a command-line interface

Use the label command to set the label of a volume. The following example sets the label for the C: drive to be System Volume:

> label c: System Volume

Warning

Do not put quotes around multiword labels. The label command captures everything after the drive parameter so no quotes are necessary.

Using VBScript

' This code sets the label of a volume.
' The Win32_Volume class is new in Windows Server 2003
' ------ SCRIPT CONFIGURATION ------
strComputer = "."
strDrive = "<Drive>"  ' e.g., C:
strLabel = "<Label>"  ' e.g., System Volume
' ------ END CONFIGURATION ---------
set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
set colVol = objWMI.ExecQuery("select * from Win32_Volume where Name = '" & _
                              strDrive & "\\'")
if colVol.Count <> 1 then
   WScript.Echo "Error: Volume not found."
else
   for each objVol in colVol
      objVol.Label = strLabel
      objVol.Put_
      WScript.Echo "Successfully set label for volume."
   next 
end if

Discussion

The label of a volume is nothing more than a short description that is displayed in tools such as Windows Explorer when you view the list of drives. A label can contain up to 32 ...

Get Windows Server Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.