Recipe 3.6. Setting the Label of a VolumeProblemYou want to set the label of a volume. SolutionUsing a graphical user interface
Using a command-line interfaceUse 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
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 DiscussionThe 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 characters. You can use a mix of alphanumeric and special characters. Also, labels do not have to be unique across volumes, but it defeats the purpose of having labels in the first place if you configure multiple volumes with the same one. And unlike setting drive letters, you can modify the label of a volume regardless of whether the volume is the system volume or has files that are locked. |