9 Ağustos 2020 Pazar

GetDriveType metodu

Giriş
Çağrı sonucu olarak şunu döner
DRIVE_UNKNOWN - 0 - The drive type cannot be determined.

DRIVE_NO_ROOT_DIR - 1 - The root path is invalid; for example, there is no volume mounted at the specified path.

DRIVE_REMOVABLE - 2 - The drive has removable media; for example, a floppy drive, thumb drive, or flash card reader.

DRIVE_FIXED - 3 - The drive has fixed media; for example, a hard disk drive or flash drive.

DRIVE_REMOTE - 4 - The drive is a remote (network) drive.

DRIVE_CDROM - 5 - The drive is a CD-ROM drive.

DRIVE_RAMDISK - 6 - The drive is a RAM disk.
Örnek
Şöyle yaparız
#include <windows.h>
int main()
{
  wchar_t basePath[1024]{ L"" }, volName[1024]{ L"" };
  GetModuleFileName(NULL, basePath, 1024);
  GetVolumePathName(basePath, volName, 1024);

  UINT type = GetDriveType(volName);
  if (type == 2)
  {
    MessageBox(NULL, L"You are running from a flash drive (USB)",L"",MB_OK);
  }
  else
  {
    MessageBox(NULL, L"You are NOT running from a flash drive (USB)",L"", MB_OK);
  }
}

Hiç yorum yok:

Yorum Gönder