I have written three different methods that make use of native CreateFile
and DeviceIoControl
calls in order to retrieve the HDD Serial Number (not the
Your code actually runs OK for me, i.e. it returns the same data as the other methods described in the referenced thread. The only change I had to make was from:
serial = Encoding.ASCII.GetString(result.Buffer, 0, result.Buffer.Length)
.Replace("\0", String.Empty)
.Trim();
To:
serial = Encoding.ASCII.GetString(result.Buffer, 0, result.Buffer.Length)
.Substring(IntPtr.Size)
.Replace("\0", String.Empty)
.Trim();