PC Review


Reply
Thread Tools Rate Thread

Using IOCTL_DISK_GET_DRIVE_GEOMETRY_EX through DeviceIoControl()

 
 
New Member
Join Date: Apr 2007
Posts: 2
 
      29th Apr 2007
/* Can anybody help me? The following code is intended to get the HDD Signature. It's returning error 998 although i am running it under an administrator account*/

#include <iostream>
using namespace std;

#ifndef WINVER
#define WINVER 0x0501
#endif

#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0501
#endif

#include <windows.h>
#include "Winioctl.h"

int main()
{
HANDLE hPhysicalDrive = CreateFile(
"\\\\.\\PhysicalDrive0",
FILE_ALL_ACCESS,
FILE_SHARE_READ|FILE_SHARE_WRITE,
0,
OPEN_EXISTING,
0,
NULL);

if(hPhysicalDrive==INVALID_HANDLE_VALUE)
{
cout<<"Can\'t open device"<<endl;
return 0;
}

DWORD bytesRet;
DRIVE_LAYOUT_INFORMATION_EX* dlix = (DRIVE_LAYOUT_INFORMATION_EX*)malloc(5120);//Just to ensure enough space

if(dlix==NULL)
{
cout<<"Memory Allocation failed"<<endl;
CloseHandle(hPhysicalDrive);
return 0;
}

BOOL ioctlSucceed = DeviceIoControl(
hPhysicalDrive,
IOCTL_DISK_GET_DRIVE_GEOMETRY_EX,
NULL,
0,
(LPVOID)&dlix,
5120,
(LPDWORD)&bytesRet,
NULL);

if(ioctlSucceed)
{
cout<<"Success"<<endl;
cout<<"Number of partitions: "<<dlix->PartitionCount<<endl;
switch(dlix->PartitionStyle)
{
case 0://MBR
cout<<"Partition style is MBR"<<endl;
cout<<"Signature in hex: "<<hex<<uppercase<<dlix->Mbr.Signature<<endl;
break;
case 1://GPT
cout<<"Partition style is GPT"<<endl;
break;
case 2://RAW
cout<<"Partition style is RAW"<<endl;
break;
}
}
else
{
cout<<"DeviceIoControl failed with error: "<<GetLastError()<<endl;
//Output: DeviceIoControl failed with error: 998
}

free((void*)dlix);
CloseHandle(hPhysicalDrive);
return 0;
}
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Http Post of XML works through Code Behind but fails through Class =?Utf-8?B?VGVybWluYXRvcnM=?= Microsoft Dot NET Framework 0 4th Aug 2004 01:31 AM
Can't browse through IE but can through Search Internet Lauri Windows XP Internet Explorer 0 16th May 2004 08:27 PM
Now cannot connect to internet through LAN desktop though can through wireless laptops Chris Windows XP Networking 1 12th Mar 2004 05:20 AM
I can only get a IE web page through Outlook, not through IE alone. Nick Windows XP Internet Explorer 1 8th Dec 2003 05:07 PM
Which is more efficient and user-friendly: Using forms for the databases through Access or through forms created in VB? A Future Computer Scientist Microsoft Access 13 26th Sep 2003 11:41 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:33 PM.