/*
GetVolumeNameForVolumeMountPoint.Cpp
参考:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa365238(v=vs.85).aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/aa364037(v=vs.85).aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/aa365717(v=vs.85).aspx
*/
#include <Windows.h>
#define BUFSIZE MAX_PATH
int MountedFolder( TCHAR * szVolumeMountPoint , TCHAR * szVolumeMountPoint2 )
{
BOOL bFlag;
TCHAR Buf[BUFSIZE]; // temporary buffer for volume name
// We should do some error checking on the inputs. Make sure there
// are colons and backslashes in the right places, and so on
bFlag = GetVolumeNameForVolumeMountPoint(
szVolumeMountPoint2, // input volume mount point or directory
Buf, // output volume name buffer
BUFSIZE); // size of volume name buffer
if (bFlag != TRUE) {
int x = GetLastError();//2 系统找不到指定的文件。
return (-2);
}
//_tprintf( TEXT("Volume name of %s is %s\n"), argv[2], Buf );
bFlag = SetVolumeMountPoint(
szVolumeMountPoint, // mount point
Buf); // volume to be mounted
if (bFlag == 0) {
int x = GetLastError();
x = 0;//目录不是空的。 0x00000091 还有0x57 系统找不到指定的文件。
}
return (bFlag);
}
void EnumeratingVolumeGUIDPaths()
{
BOOL bFlag;
TCHAR Buf[BUFSIZE]; // temporary buffer for volume name
TCHAR Drive[] = TEXT("c:\\"); // template drive specifier
TCHAR I; // generic loop counter
// Walk through legal drive letters, skipping floppies.
for (I = TEXT('c'); I < TEXT('z'); I++ )
{
// Stamp the drive for the appropriate letter.
Drive[0] = I;
bFlag = GetVolumeNameForVolumeMountPoint(
Drive, // input volume mount point or directory
Buf, // output volume name buffer
BUFSIZE ); // size of volume name buffer
if (bFlag) {
_tprintf (TEXT("The ID of drive \"%s\" is \"%s\"\n"), Drive, Buf);
}
}
}
int _tmain(int argc, _TCHAR* argv[])
{
//这两个必须存在,不然返回错误。
wchar_t * path = L"d:\\test\\";//必须为空。
wchar_t * Volume = L"f:\\";
int x = MountedFolder(path , Volume );
BOOL bFlag = DeleteVolumeMountPoint(path);// Path of the volume mount point
EnumeratingVolumeGUIDPaths();
return 0;
}
没有评论:
发表评论