Программа, выводящая информацию о логических дисках


Программа, выводящая информацию о логических дисках

Ход работы

#include "stdafx.h"

#include <windows.h>

#include <stdio.h>

#define _WIN32_WINNT 0x0501

#define BUFSIZE MAX_PATH

#define FILESYSNAMEBUFSIZE MAX_PATH

DWORD mydrives = 100;

char lpBuffer[100];

TCHAR szDrive[] = _T(" A:");

LPCWSTR drive2[13] = {L"A:", L"B:", L"C:", L"D:", L"E:", L"F:", L"G:", L"H:",L"I:", L"J:", L"K:", L"L:"};

int main(void)

{

// выводит размер диска, свободное место, кластеры

LPCWSTR pszDrive = NULL;

BOOL test1, fResult;

__int64 lpFreeBytesAvailable, lpTotalNumberOfBytes, lpTotalNumberOfFreeBytes;

DWORD dwSectPerClust, dwBytesPerSect, dwFreeClusters, dwTotalClusters;

test1 = GetDiskFreeSpaceEx(

pszDrive,

  • (PULARGE_INTEGER)&lpFreeBytesAvailable,
  • (PULARGE_INTEGER)&lpTotalNumberOfBytes,
  • (PULARGE_INTEGER)&lpTotalNumberOfFreeBytes

);

printf(" Using GetDiskFreeSpaceEx()... ");

printf("The return value: %d, error code: %d ", test1, GetLastError());

printf("Total number of free bytes available for user-caller: %ul ", lpFreeBytesAvailable);

printf("Total number of bytes available for user: %ul ", lpTotalNumberOfBytes);

printf("Total number of free bytes on disk: %ul ", lpTotalNumberOfFreeBytes);

fResult = GetDiskFreeSpace(pszDrive,

&dwSectPerClust,

&dwBytesPerSect,

&dwFreeClusters,

&dwTotalClusters);

printf(" Using GetDiskFreeSpace()... ");

printf("The return value: %d, error code: %d ", fResult, GetLastError());

printf("Sector per cluster = %ul ", dwSectPerClust);

printf("Bytes per sector = %ul ", dwBytesPerSect);

printf("Free cluster = %ul ", dwFreeClusters);

printf("Total cluster = %ul ", dwTotalClusters);

printf("Total free bytes = %ul ", (dwFreeClusters*dwSectPerClust*dwBytesPerSect));

printf(" ");

// выводит тип диска

int i;

UINT test2;

for(i=0; i<12; i++)

{

test2 = GetDriveType(drive2[i]);

switch(test2)

{

case 0: printf("Drive %S is type %d - Cannot be determined. ", drive2[i], test2);

break;

case 1: printf("Drive %S is type %d - Invalid root path/Not available. ", drive2[i], test2);

break;

case 2: printf("Drive %S is type %d - Removable. ", drive2[i], test2);

break;

case 3: printf("Drive %S is type %d - Fixed. ", drive2[i], test2);

break;

case 4: printf("Drive %S is type %d - Network. ", drive2[i], test2);

break;

case 5: printf("Drive %S is type %d - CD-ROM. ", drive2[i], test2);

break;

case 6: printf("Drive %S is type %d - RAMDISK. ", drive2[i], test2);

break;

default : "Unknown value! ";

}

}

printf(" ");

// выводит номер тома, буфер, название

char buf[BUFSIZE];

DWORD lpMaximumComponentLength;

DWORD dwSysFlags;

char FileSysNameBuf[FILESYSNAMEBUFSIZE];

BOOL test;

HANDLE hVol;

hVol = FindFirstVolume((LPWSTR)buf, BUFSIZE);

if(hVol == INVALID_HANDLE_VALUE)

{

printf ("No volumes found! ");

return (1);

}

test = GetVolumeInformation(

(LPCWSTR)buf,

NULL,

BUFSIZE,

NULL,

&lpMaximumComponentLength,

&dwSysFlags,

(LPWSTR)FileSysNameBuf,

FILESYSNAMEBUFSIZE

);

printf("The GetVolumeInformation() return value is: %d ", test);

printf("The first volume found: %S ", buf);

printf("The buffer for volume name: %d ", BUFSIZE);

printf("The max component length: %d ", lpMaximumComponentLength);

printf("The file system flag: %d ", dwSysFlags);

printf("The file system: %S ", FileSysNameBuf);

printf("The buffer for file system name: %d ", FILESYSNAMEBUFSIZE);

if(FindVolumeClose(hVol) != 0)

printf("Handle for the %S closed successfully! ", buf);

else

printf("%S handle failed to close! ");

//

DWORD uDriveMask = GetLogicalDrives();

printf("The bitmask of the logical drives in hex: %0X ", uDriveMask);

printf("The bitmask of the logical drives in decimal: %d ", uDriveMask);

if(uDriveMask == 0)

printf("GetLogicalDrives() failed with failure code: %d ", GetLastError());

else

{

printf("This machine has the following logical drives: ");

while(uDriveMask)

{

if(uDriveMask & 1)

printf("%S ", (const char *)szDrive);

++szDrive[1];

uDriveMask >>= 1;

}

printf(" ");

}

system ("pause");

// смешение битовой маски всех дисков

DWORD test3;

int l;

test3 = GetLogicalDriveStrings(mydrives, (LPWSTR)lpBuffer);

if(test3 != 0)

{

printf("GetLogicalDriveStrings() return value: %d, Error (if any): %d ", test3, GetLastError());

printf("The logical drives of this machine are: ");

for(l = 0; i<100; i++)

printf("%c", lpBuffer[i]);

printf(" ");

}

else

printf("GetLogicalDriveStrings() is failed lor!!! Error code: %d ", GetLastError());

return 0;

} программа информация диск