Информация о жестком диске

Данный код показывает техническую информацию об жеском диске ( физический размер , кол-во физических секторов и пр.). Скомпилированная программа требует прав администратора!

Платформа: Windows

#DEFINE WIN_INCLUDEALL
#INCLUDE "windows.bi"

#DEFINE szDrive "\\.\PhysicalDrive0"

Dim As DISK_GEOMETRY dg
Dim As GET_LENGTH_INFORMATION gli
Dim As Ulongint ullDiskSize
Dim As BOOL bResult
Dim As DWORD iReturnBytes
Dim As HANDLE hDevice = INVALID_HANDLE_VALUE

hDevice = CreateFile(szDrive,                   _
GENERIC_READ Or GENERIC_WRITE,                  _
FILE_SHARE_READ Or  _
FILE_SHARE_WRITE,   _
NULL,                       _
OPEN_EXISTING,      _
0,                  _
NULL)

If (hDevice = INVALID_HANDLE_VALUE)  Then

Else

    bResult = DeviceIoControl(hDevice,      _
    IOCTL_DISK_GET_DRIVE_GEOMETRY,  _
    NULL, 0,                        _
    @dg, Sizeof(dg),                _
    @iReturnBytes,                          _
    NULL)
    iReturnBytes = 0

    If bResult = FALSE Then

        Print "Geometry failed. Error = " & GetLastError ()

    Endif

    bResult = DeviceIoControl(hDevice,          _
    IOCTL_DISK_GET_LENGTH_INFO, _
    NULL, 0,                        _
    @gli, Sizeof(gli),              _
    @iReturnBytes,                          _
    NULL)

    If bResult = FALSE Then

        Print "LengthInfo failed. Error = " & GetLastError ()

    Endif

    CloseHandle(hDevice)

Endif

If (bResult) Then

    ullDiskSize  = gli.Length.quadpart

    ? "Cylinders = " & dg.Cylinders.QuadPart
    ? "Tracks per cylinder = " & dg.TracksPerCylinder
    ? "Sectors per track = " & dg.SectorsPerTrack
    ? "Bytes per sector = " & dg.BytesPerSector
    ? "Physical sectors = " & ullDiskSize\dg.BytesPerSector
    ? "Size disk in bytes = " & ullDiskSize
    Print Using "Size disk in gigabytes = ###.##" ; ullDiskSize / (1024 * 1024 * 1024)

Else

    Print "Failed. Error = " & GetLastError ()
    
Endif


Sleep