Pas de dépendances
#include <windows.h> #include <tchar.h> #include <stdio.h> #include <string.h> void type(LPCTSTR lecteur) { char* Stype[7] = {"inconnu","invalide","amovible","fixe","reseau","cdrom","ramdisk"}; int type = GetDriveType(lecteur); printf(" type = %s\n",Stype[type]); } BOOL informations(LPCTSTR lecteur) { TCHAR nom[500]; TCHAR filesystemname[500]; DWORD serialnum; DWORD MaximumComponentLength; DWORD flags; BOOL ret = GetVolumeInformation(lecteur,nom,500,&serialnum,&MaximumComponentLength,&flags,filesystemname,500); if (ret) { _tprintf(_T(" nom : %s\t serial : %X maxcomp : %d\n flags : %X systname : %s\n"),nom,serialnum,MaximumComponentLength,flags,filesystemname); return TRUE; } else { printf(" infos indisponibles\n"); return FALSE; } } void freespace(LPCTSTR lecteur) { DWORD sectors,octetsparsect,numfreeclusts,totalclust; GetDiskFreeSpace(lecteur,§ors,&octetsparsect,&numfreeclusts,&totalclust); printf(" secteurs : %u\t oct/sect : %u\t clustlibres :%u\t totalclust :%u\n",sectors,octetsparsect,numfreeclusts,totalclust); printf(" octets total : %u \t libres : %u\t -> %.1f%%\n",sectors*octetsparsect*totalclust,sectors*octetsparsect*numfreeclusts,numfreeclusts*100.0/totalclust); } void Analyse(LPCTSTR lecteur) { int res; type(lecteur); res = informations(lecteur); if (res == 0) { printf("\n"); return; } freespace(lecteur); printf("\n"); } void InterpreterChaine(LPCTSTR buf) { int curs = 0; printf("Interpretation buffer (GetLogicalDriveStrings)\n"); while(buf[curs]!='\0') { int len = _tcslen(buf); // strlen, ou wcslen selon UNICODE actif ou non. printf("Lecteur %s present : \n",buf+curs); Analyse(buf+curs); curs+=len+1; } } int main() { TCHAR buf[5000]; GetLogicalDriveStrings(5000,buf); InterpreterChaine(buf); return 0; }
No explanations yet.