Creating a Mounted Folder Program Example
From the user point of view we can mount a drive/volume/partition to an NTFS empty folder as stated in the following steps. This will allow you to use a hard-drive as a normal folder on your main system drive and will be useful in many cases in managing your local storage. For example if you have made your original system drive/partition too small for your growing software needs or if you just want to be able to access multiple drives via one single drive letter.
The following sample demonstrates how to create a mounted folder programmatically. This sample uses the following functions: GetVolumeNameForVolumeMountPoint() and SetVolumeMountPoint().
Create a new Win32 console application project and give a suitable project name.
Add the source file and give a suitable name.
Add the following source code.
// The following #define already defined in the SDK
// For Windows Server 2003, Windows XP
// #define _WIN32_WINNT 0x0501
#define BUFSIZE MAX_PATH
int wmain(int argc, WCHAR *argv)
WCHAR Buf[BUFSIZE]; // temporary buffer for volume name
if(argc != 3)
wprintf(L"Usage: %s <mount_point> <volume>\n", argv );
wprintf(L" Example, \"%s c:\\mnt\\fdrive\\ f:\\\"\n", argv);
wprintf(L" ...mount the f: volume to c:\\mnt\\fdrive folder\n");
// We should do some error checking on the inputs. Make sure
// there are colons and backslashes in the right places, etc.
bFlag = GetVolumeNameForVolumeMountPoint(
argv, // input volume mount point or directory
Buf, // output volume name buffer
BUFSIZE // size of volume name buffer
if (bFlag != TRUE)
wprintf(L"Retrieving volume name for %s failed.\n", argv);
wprintf(L"Volume name of %s is %s\n", argv, Buf);
bFlag = SetVolumeMountPoint(
argv, // mount point
Buf // volume to be mounted
wprintf(L"Attempt to mount %s at %s failed.\n", argv, argv);
wprintf(L"Error code is %d\n", GetLastError());
wprintf(L"%s was mounted on %s successfully!\n", argv, argv);
Build and run the project. The following screenshot is an output sample.
The following sample output shows a thumb drive (G:) was mounted on the C:\testmountdrive folder.
The following Figure shows the mounted drive on folder testmountdrive seen in the Windows explorer and the property page of the mounted drive.