Recipe3.6.Setting the Label of a Volume


Recipe 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

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



Windows Server Cookbook
Windows Server Cookbook for Windows Server 2003 and Windows 2000
ISBN: 0596006330
EAN: 2147483647
Year: 2006
Pages: 380
Authors: Robbie Allen

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net