Click here to Skip to main content
15,889,808 members
Articles / Programming Languages / C#

Get Physical HDD Serial Number without WMI

Rate me:
Please Sign up or sign in to vote.
4.79/5 (63 votes)
6 May 2008CPOL2 min read 960.5K   62.7K   178  
Retrieve the physical Hard drive ID and other info using low level APIs like DeviceIOControl
#pragma once
using namespace System;
using namespace System::Runtime::InteropServices;
using namespace System::Collections::Generic;

namespace IOEx {
	public ref class DriveListEx : System::Collections::Generic::List<DriveInfoEx ^>
	{
		UINT m_count = 0;
	public:

		DriveListEx(void)
		{
				DiskInfo& di = DiskInfo::GetDiskInfo();
				di.LoadDiskInfo();
				m_count = di.m_DriveCount;
				for(UINT i=0; i < m_count; i++)
					this->Add<DriveInfoEx^>(new DriveInfoEx(i));
				//String^ ms = di.GetSerialNumber(0);
				//ms =di.GetDriveType(0);
				//ms = di.GetModelNumber(0);
				//ms = di.GetRevisionNumber(0);
				//unsigned __int64 size = di.DriveSize(0);
				//size = di.BufferSize(0);
		}

		virtual ~DriveListEx(void)
		{
		}
	};
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
Decebal Mihailescu is a software engineer with interest in .Net, C# and C++.

Comments and Discussions