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 |
|
|
Library |
|
|
DLL |
|
|
Unicode and ANSI names | FindFirstVolumeW (Unicode) and FindFirstVolumeA (ANSI) |
See also
Send comments about this topic to Microsoft
Build date: 4/17/2012
__out LPTSTR lpszVolumeName,
__in DWORD cchBufferLength
);
- 4/30/2012
- izzy sablan
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
- 7/15/2011
- cjalbert
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);
}
}
- 4/22/2010
- yair k