Hi,
Can anybody tell me how to access hard disk partition information or MBR content through Visual C++ Programming?
Suggest me how should i do programming and which API i should use for this purpose.
Bye.....

Recommended Answers

All 9 Replies

Hi,
Thanks for your reply. I got the very useful information.
Can i get any code samples regarding this hard disk access? please send, if any.

Thanks & Regards.

I could, but I'd rather see how good you are at digging out information for yourself.
Try using the information, don't just thank me for it.

The only thing I would add is make sure you're testing this on a machine you don't mind trashing. You're only a few keystrokes away from "Damn, where are my install disks" because you've completely trashed your hard disk.

Hi Salem,
I find out how to read hard disk programmatically in Visual C++ by using CreateFile and DeviceIoControl function.
But I am not able find the file vwin32.vxd in windows xp operating system for getting the disk information.
This vwin32.vxd will only exist in win9x series. so, is there any alternative for this in windows xp.
Please solve my problem.

Bye....

Hi,
I found out some useful information from "Physical Disks and Volumes" but still i am not able to read data from hard disk sectors.

Bye...

OK, getting bored of you saying "it doesn't work" and you NOT posting the code.
Since I'm not interested in playing 20 questions just to figure out which of many 1000's of possible mistakes you might have made, I'm done here.

Hi Salem,
I need some help from you regarding the extended boot record.
May i know exactly where the EBR will be present? I found starting sector location of extended partition. I am expecting the EBR will present in this starting sector of Extended partition. But the last two bytes of that sector is not equal to 55 AA.
Then how could i know whether this sector is the one i m expecting as ebr? How could i know the exact location of EBR?
Please reply me as quickly as possible..........
Bye....

The following piece of code works exactly as what you want to do, I use this method to write my own MBR boot loader code for booting into multiple OS selectively (holding Ctrl to boot into Ubuntu, holding Alt to boot into Window 98, otherwise boot into Window XP):

int		res;
	DWORD	nRead, nWritten;
	char	buf[4096];
	MSG		msg;
	HACCEL	hAccelTable;

	HANDLE hDisk = CreateFile("\\\\.\\PhysicalDrive0", GENERIC_READ | GENERIC_WRITE,
		FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
	res = SetFilePointer(hDisk, 0, 0, FILE_BEGIN);
	res = ReadFile(hDisk, buf, 512, &nRead, NULL);
	res = WriteFile(hDisk, buf, 512, &nWritten, NULL);
	CloseHandle(hDisk);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.