BOOL ChangeMountPoint(int nDriveNo, LPCTSTR lpDevice, BOOL bAddMountPoint)
{
BOOL bResult = FALSE;
TCHAR szDriveLetterAndSlash[4] = { 0 };
TCHAR szDriveLetter[3] = { 0 };
TCHAR szUniqueVolumeName[MAX_PATH] = { 0 };
szDriveLetter[0] = (WCHAR)(nDriveNo + L'A');
szDriveLetter[1] = TEXT(':');
szDriveLetter[2] = TEXT('\0');
szDriveLetterAndSlash[0] = (WCHAR)(nDriveNo + L'A');
szDriveLetterAndSlash[1] = TEXT(':');
szDriveLetterAndSlash[2] = TEXT('\\');
szDriveLetterAndSlash[3] = TEXT('\0');
if (bAddMountPoint)
{
//Try to Attach lpDevice to lpDriveLetter
bResult = DefineDosDevice(DDD_RAW_TARGET_PATH, szDriveLetter,
lpDevice);
if (bResult)
{
if (!GetVolumeNameForVolumeMountPoint(szDriveLetterAndSlash,
szUniqueVolumeName,
MAX_PATH))
{
//Can't Find Attached lpDevice 's VolumeName
szUniqueVolumeName[0] = '\0';
}
bResult = DefineDosDevice(
DDD_RAW_TARGET_PATH | DDD_REMOVE_DEFINITION |
DDD_EXACT_MATCH_ON_REMOVE, szDriveLetter,
lpDevice);
if (!bResult)
return bResult;
bResult = SetVolumeMountPoint(szDriveLetterAndSlash,
szUniqueVolumeName);
}
}
else
{
bResult = DeleteVolumeMountPoint(szDriveLetterAndSlash);
}
return bResult;
}
CnCrypt代码 之 为磁盘设备分配和移除盘符
最新推荐文章于 2021-01-26 20:26:25 发布