FightingQ 2021-07-07 12:21 采纳率: 0%
浏览 63

获取硬盘序列号报错: IDE identify command not supported。

获取硬盘序列号报错,以下为方法,什么情况下会报 IDE identify command not supported。

          #region GetHddInfoNT

        private static HardDiskInfo GetHddInfoNT(byte driveIndex)
        {
            MessageBox.Show("GetHddInfoNT");
            GetVersionOutParams vers = new GetVersionOutParams();
            SendCmdInParams inParam = new SendCmdInParams();
            SendCmdOutParams outParam = new SendCmdOutParams();
            uint bytesReturned = 0;

            string s = string.Format(@"\\.\PhysicalDrive{0}", driveIndex);
            IntPtr hDevice = CreateFile(
             s,
             GENERIC_READ | GENERIC_WRITE,
             FILE_SHARE_READ | FILE_SHARE_WRITE,
             IntPtr.Zero,
             OPEN_EXISTING,
             0,
             IntPtr.Zero);
            if (hDevice == IntPtr.Zero)
            {
                throw new Exception("CreateFile faild.");
            }

            int handel = DeviceIoControl(
             hDevice,
             DFP_GET_VERSION,
             IntPtr.Zero,
             0,
             ref vers,
             (uint)Marshal.SizeOf(vers),
             ref bytesReturned,
             IntPtr.Zero);
            if (0 == handel)
            {
                CloseHandle(hDevice);
                return new HardDiskInfo();
            }
            MessageBox.Show(vers.fCapabilities.ToString());
            if (0 == (vers.fCapabilities & 1))
            {
                CloseHandle(hDevice);
                throw new Exception("Error: IDE identify command not supported.  GetHddInfoNT");
            }
            if (0 != (driveIndex & 1))
            {
                inParam.irDriveRegs.bDriveHeadReg = 0xb0;
            }
            else
            {
                inParam.irDriveRegs.bDriveHeadReg = 0xa0;
            }
            inParam.irDriveRegs.bCommandReg = 0xec;
            inParam.bDriveNumber = driveIndex;
            inParam.irDriveRegs.bSectorCountReg = 1;
            inParam.irDriveRegs.bSectorNumberReg = 1;
            inParam.cBufferSize = 512;

            if (0 == DeviceIoControl(
             hDevice,
             DFP_RECEIVE_DRIVE_DATA,
             ref inParam,
             (uint)Marshal.SizeOf(inParam),
             ref outParam,
             (uint)Marshal.SizeOf(outParam),
             ref bytesReturned,
             IntPtr.Zero))
            {
                CloseHandle(hDevice);
                throw new Exception("DeviceIoControl failed: DFP_RECEIVE_DRIVE_DATA");
            }
            CloseHandle(hDevice);

            return GetHardDiskInfo(outParam.bBuffer);
        }

        #endregion
  • 写回答

2条回答 默认 最新

  • 微软技术分享 全栈领域优质创作者 2023-06-06 16:40
    关注

    您好,看了一下你的代码大体上是使用DeviceIoControl来获取硬盘序列号的,这是一种很常见的读取方式,一般情况下当硬盘类型不支持,驱动程序问题,或者是系统环境限制等,都可能会出现此类错误。

    评论
  • weixin_44873882 2023-07-10 15:53
    关注

    没有使用管理员权限运行吧

    评论

报告相同问题?

悬赏问题

  • ¥15 mysql游戏好友添加怎么设计啊?
  • ¥30 关于#开发语言#的问题:我需要在抄板的基础上再抄板抄程序,根据RDA8851CM基础上开发
  • ¥15 oracle 多个括号,怎么删除指定的括号及里面的内容?
  • ¥15 poly函数表达式的看法
  • ¥15 我想问一下有人熟悉思科packet tracer
  • ¥15 小新14API2019想用bios调风扇
  • ¥15 Python和易语言爬虫探讨
  • ¥15 有Sakai 会吗,没做过,需要交
  • ¥20 使用vba登录公司统一登录的网页
  • ¥15 opensea上传人机验证不了