I want to enumerate all available drive letters (which aren\'t already taken) in Windows using VC++.
How can I do this?
Im not shure how to enumerate them or if it will compile on visual c++ but I sturm-coded this on Dev C++ or Code Blocks to check what drive is acessible by using CreateFile and what type of drive is by using GetDriveType. Program checks drives from A to Z:
#include
#include
#include
#include
using namespace std;
int __stdcall WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmdLine, INT nShowCmd)
{
HANDLE hDevice = NULL;
HANDLE fileFind = NULL;
while(true)
{
Sleep(3005);
char drv='A';
while(drv!='[')
{
Sleep(105);
const char *charDrvCF;
const char *charDrv;
stringstream Str;
string drvStr;
Str<>drvStr;
string drvSpc=drvStr+":\\";
string fCheck="\\\\.\\";
string fhCheck=fCheck+drvStr+":";
charDrvCF=fhCheck.c_str();
charDrv=drvSpc.c_str();
hDevice=CreateFile(charDrvCF,
GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
0,
NULL);
if(hDevice!=INVALID_HANDLE_VALUE)
{
switch(GetDriveType(charDrv))
{
case DRIVE_FIXED:
{
cout<<"Fixed drive detected: "<