Windows API 第20篇 SetVolumeMountPoint 设置卷挂载点参数错误
函数原型:
BOOL SetVolumeMountPoint(
IN LPCTSTR lpszVolumeMountPoint, // mount point
IN LPCTSTR lpszVolumeName // volume to be mounted
);
参数:
lpszVolumeMountPoint:要设置的挂载点,如:“C:\\MyDrive\\DDrive\\”, 必须以反斜杠'\'结尾
lpszVolumeName :指定的卷名,这个卷名必须为全局标志符(GUID),像
\\?\Volume{fe04a016-a8fc-11e4-824b-806e6f6e6963}\ 这种形式。得到GUID的方法有很多,调用GetVolumeName,
GetVolumeNameForVolumeMountPoint 都可以得到。
下面为我的F盘设置一个挂载点:
int _tmain(int argc, _TCHAR* argv[]) { CHAR szVolumeName[MAX_PATH] = { 0 }; BOOL bRet = GetVolumeNameForVolumeMountPointA("F:\\", szVolumeName, MAX_PATH); //这里要注意了,"C:\\share\\"目录一定要存在,而且必须为空的,否则会返回nErr = 0x57错误,为参数错误 bRet = SetVolumeMountPointA("C:\\Share\\", szVolumeName); int nErr = GetLastError(); return 0; }
就是这些话:
It is an error to attempt to mount a volume on a directory that has any files or subdirectories in it. This error occurs for system and hidden directories as well as other directories, and it occurs for system and hidden files.
posted on 2018-10-08 17:07 priarieNew 阅读(1686) 评论(0) 编辑 收藏 举报