C#/Native: Reading HDD Serial Using SCSI PassThrough

前端 未结 1 403
天命终不由人
天命终不由人 2021-01-22 09:13

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

1条回答
  •  臣服心动
    2021-01-22 09:47

    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();
    

    0 讨论(0)
提交回复
热议问题