SetVolumeLabel function (Windows)

Switch View :
ScriptFree
SetVolumeLabel function

Applies to: desktop apps only

Sets the label of a file system volume.

Syntax

BOOL WINAPI SetVolumeLabel(
  __in_opt  LPCTSTR lpRootPathName,
  __in_opt  LPCTSTR lpVolumeName
);

Parameters

lpRootPathName [in, optional]

A pointer to a string that contains the volume's drive letter (for example, X:\) or the path of a mounted folder that is associated with the volume (for example, Y:\MountX\). The string must end with a trailing backslash ('\'). If this parameter is NULL, the root of the current directory is used.

lpVolumeName [in, optional]

A pointer to a string that contains the new label for the volume. If this parameter is NULL, the function deletes any existing label from the specified volume and does not assign a new label.

Return value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

A label is a user-friendly name that a user assigns to a volume to make it easier to recognize. A volume can have a label, a drive letter, both, or neither. For more information, see Naming a Volume.

Requirements

Minimum supported client

Windows XP

Minimum supported server

Windows Server 2003

Header

WinBase.h (include Windows.h)

Library

Kernel32.lib

DLL

Kernel32.dll

Unicode and ANSI names

SetVolumeLabelW (Unicode) and SetVolumeLabelA (ANSI)

See also

GetVolumeInformation
Volume Management Functions

 

 

Send comments about this topic to Microsoft

Build date: 4/17/2012

Community Content

Thomas Lee
Alternative to using unmanaged API

As an alternative to using this unmanaged API, consider looking at System.IO.DriveInfo and it's VolumeLabel property. See http://msdn.microsoft.com/en-us/library/system.io.driveinfo.aspx for more information on the DriveInfo class, and see http://msdn.microsoft.com/en-us/library/system.io.driveinfo.volumelabel.aspx for information in the VolumeLabel property.


dmex
C# syntax
[DllImport("kernel32.dll", CharSet=CharSet.Auto, SetLastError=true)]
internal static extern bool SetVolumeLabel(string driveLetter, string volumeName);

dmex
vb.net syntax
<DllImport("kernel32.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
Public Shared Function SetVolumeLabel(ByVal driveLetter As String, ByVal volumeName As String) As Boolean
End Function