Bienvenido a Tecnohackers

Tecnohackers » Programacion » Area de Programacion » Programacion a Bajo Nivel. APIs, Hooking, ASM, C/C++, etc.
 » 

[C] Enumerar unidades (Windows)



Autor Tema: [C] Enumerar unidades (Windows)  (Leído 1009 veces)

Desconectado pax01

  • Recien Llegado
  • *
  • Mensajes: 23
[C] Enumerar unidades (Windows)
« en: Marzo 19, 2013, 12:01:25 am »
Enumera las unidades actuales y su tipo.

Código: You are not allowed to view links. Register or Login
//Compilado en Dev C++ MinGw
//Codigo por Leonardo Adrian Reichert
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>

short ExistDriveIndex(int drive){
    int drives, i;
    if((drives=GetLogicalDrives())==0)
        return -1;
   
    for(i=1; drive>0; drive--)
        i*=2;
       
    return ((drives&i)==i);
    }

short GetLastDrive(){
    int drives;
    if((drives=GetLogicalDrives())==0)
        return -1;
   
    int i=0;
    while((drives>>i)!=0){
        i++;
        }
   
    return i-1;
    //i-1 valor is the last char drive
    //a=0, z=25
    //a... m... z
    }

int main(int argc, char *argv[])
{


printf("*** Unidades actuales ***\n");
char sDrive[3];
int i;
for(i=0; i<=GetLastDrive(); i++)
    if(ExistDriveIndex(i)){
        sprintf(sDrive, "%c:", i+65);
       
        switch( GetDriveTypeA(sDrive) ){
            case DRIVE_UNKNOWN:
                printf(" %s\tunidad desconocida.\n", sDrive);
                break;
            case DRIVE_NO_ROOT_DIR:
                printf(" %s\tunidad sin asignar.\n", sDrive);
                break;
            case DRIVE_REMOVABLE:
                printf(" %s\tunidad extraible.\n", sDrive);
                break;
            case DRIVE_FIXED:
                printf(" %s\tunidad de disco duro.\n", sDrive);
                break;
            case DRIVE_REMOTE:
                printf(" %s\tunidad de disco remoto (red) de control.\n", sDrive);
                break;
            case DRIVE_CDROM:
                printf(" %s\tunidad de CD-ROM.\n", sDrive);
                break;
            case DRIVE_RAMDISK:
                printf(" %s\tunidad de disco RAM.\n", sDrive);
                break;
            }
        }

system("PAUSE");
return 0;
}
 

Ejemplo:

*** Unidades actuales ***

A: unidad extraible.
C: unidad de disco duro.
D: unidad de disco duro.
E: unidad extraible.
F: unidad extraible.
G: unidad extraible.
H: unidad extraible.
I: unidad de CD-ROM.
J: unidad de disco duro.
K: unidad de CD-ROM.
L: unidad de CD-ROM.
M: unidad extraible.
Presiona una tecla para continuar...

Fuente: sokoleonardo el - hacker


 


SMF 2.0.19 | SMF © 2016, Simple Machines
Paginas Afiliadas
Twitter - FaceBook - Daraxblog
Designed by Smf Personal