3 out of 6 rated this helpful - Rate this topic

FindFirstVolume function

Applies to: desktop apps only

Retrieves the name of a volume on a computer. FindFirstVolume is used to begin scanning the volumes of a computer.

Syntax

HANDLE WINAPI FindFirstVolume(
  __out  LPTSTR lpszVolumeName,
  __in   DWORD cchBufferLength
);

Parameters

lpszVolumeName [out]

A pointer to a buffer that receives a null-terminated string that specifies a volume GUID path for the first volume that is found.

cchBufferLength [in]

The length of the buffer to receive the volume GUID path, in TCHARs.

Return value

If the function succeeds, the return value is a search handle used in a subsequent call to the FindNextVolume and FindVolumeClose functions.

If the function fails to find any volumes, the return value is the INVALID_HANDLE_VALUE error code. To get extended error information, call GetLastError.

Remarks

The FindFirstVolume function opens a volume search handle and returns information about the first volume found on a computer. After the search handle is established, you can use the FindNextVolume function to search for other volumes. When the search handle is no longer needed, close it by using the FindVolumeClose function.

You should not assume any correlation between the order of the volumes that are returned by these functions and the order of the volumes that are on the computer. In particular, do not assume any correlation between volume order and drive letters as assigned by the BIOS (if any) or the Disk Administrator.

Examples

For an example, see Displaying Volume Paths.

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

FindFirstVolumeW (Unicode) and FindFirstVolumeA (ANSI)

See also

FindNextVolume
FindVolumeClose
Volume Management Functions
Mounted Folders

 

 

Send comments about this topic to Microsoft

Build date: 4/17/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
volume
HANDLE WINAPI FindFirstVolume(
  __out  LPTSTR lpszVolumeName,
  __in   DWORD cchBufferLength
);
Doesn't work with hidden volumes
The following should be included on this page:

If a volume has the VDS_VF_HIDDEN flag set, then it will not be returned by FindFirstVolume, FindNextVolume.

This information was found by reading documentation on the VDS_VOLUME_FLAG enumeration:
http://msdn.microsoft.com/en-us/library/aa383901%28VS.85%29.aspx
C# Implementation/declaration and basic usage
using System.Text;                              //! for StringBuilder
using System.Runtime.InteropServices; //! for DLL

[DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern IntPtr FindFirstVolume([Out] StringBuilder lpszVolumeName, UInt32 cchBufferLength);

Usage:
public class x
{
   public void vol()
       {
          StringBuilder volumeName = new StringBuilder(size, size);         
          bool operOk;
          IntPtr pos = WinApi.FindFirstVolume(volumeName, (uint)size);
       }
}
Note: #define _WIN32_WINNT 0x0500
Windows 2000+. #define _WIN32_WINNT 0x0500