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 |
|
|
Library |
|
|
DLL |
|
|
Unicode and ANSI names | SetVolumeLabelW (Unicode) and SetVolumeLabelA (ANSI) |
See also
Send comments about this topic to Microsoft
Build date: 4/17/2012
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.
[DllImport("kernel32.dll", CharSet=CharSet.Auto, SetLastError=true)]
internal static extern bool SetVolumeLabel(string driveLetter, string volumeName);