I would like to get file size of my external hard disk.
handle = CreateFile(L"\\\\.\\PhysicalDrive5", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL , NULL);
if (handle == INVALID_HANDLE_VALUE) {
std::cout<<"ERROR!"<<std::endl;
return -1;
}
LARGE_INTEGER size;
if(!GetFileSizeEx(handle, &size))
{
auto lastError = GetLastError();
std::cout<<"Last Error: "<<lastError<<std::endl;
CloseHandle(handle);
return -1;
}
When I execute my application with admin rights ( it is necessary for CreateFile ), I get Last Error: 1
.
OS: Windows 10, Compiler: MinGW 7.3.0
CodePudding user response:
Afaik wrong function for the object "physical disk".
User DeviceIoControl
with IOCTL_DISK_GET_DRIVE_GEOMETRY
.