程序和源代码参见附件,也可以直接从下面链接页面下载:

http://www.codeproject.com/KB/mcpp/DriveInfoEx.aspx

Introduction

Many people looking for a schema to protect their work need to get some information that is hardware specific like the Mac Address or some hard drive serial number.

Background

If you tried other solutions like like this one, it probably did not work for you because it's using the WMI services. I was able to find a solution that worked reasonably well here. It made low level calls to the disk using commands sent by the DeviceIoControlAPI. The code was not very reusable unless you used native C++. Therefore I brushed it a bit and made it look more Object Oriented. Most importantly, I exposed the drive information through a .NET collection.

Using the Code

Since the collection is written in MC++, I've included some Microsoft DLLs from the redistributable pack in the demo zip. Also it's mandatory to use .NET 2.0 since the collection is generic.

The code is very easy to use from any .NET language, like C# for instance:

Collapse|Copy Code

m_list = new DriveListEx();

m_list.Load();

//bind to a a grid view m_dataGridView.DataSource = m_list;

Points of Interest

The information about the internal drives is gathered in DiskInfo::LoadDiskInfo();

DiskInfois a native singleton class that wraps the calls to ReadPhysicalDriveInNTWithAdminRights()and ReadIdeDriveAsScsiDriveInNT(). I ignored the ReadPhysicalDriveInNTWithZeroRights()that did not seem to work anyways.

Both functions will call AddIfNew()if they can retrieve the information.

Internally there is a list that holds the raw information about the drives and that is updated when a new drive information was found.

Collapse|Copy Code

BOOL DiskInfo::AddIfNew(USHORT *pIdSector)

{

BOOL bAdd = TRUE;

for(UINT i =0; i< m_list.size();i++)

{

if(memcmp(pIdSector,m_list[i],256 * sizeof(WORD)) == 0)

{

bAdd = false;

break;

}

}

if(bAdd)

{

WORD* diskdata = new WORD[256];

::memcpy(diskdata,pIdSector,256*sizeof(WORD));

m_list.push_back(diskdata);

}

return bAdd;

}

If you are stuck with a non .NET compiler, you could still use the source code from UnmanagedCode.cpp, just uncomment the #define NATIVE_CODEline.

This build is for Windows XP 32 bit systems. If you need it for Vista or 64 bit systems, you should select the right include and lib folders when building and should not use the additional DLLs from the release.zip archive, since they are 32 bit for Windows XP.

History

Version 1.1: Added ReadPhysicalDriveInNTUsingSmartfor reading the HDD info.

P.S. I did not get a chance to test it for Windows 95 and alike.

License

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

服务器物理硬盘序列号,查看硬盘物理序列号的程序源代码相关推荐

  1. Blos查看计算机硬盘,bios查看硬盘损坏

    大家好,我是时间财富网智能客服时间君,上述问题将由我为大家进行解答. bios查看硬盘损坏的方法: 1.进入BIOS后,在"Main"或"Information" ...

  2. megacli通过盘符定位物理盘_MEGACLI查看硬盘状态

    通过megacli的如下命令查看RAID的情况,命令如下: /opt/MegaRAID/MegaCli/MegaCli64 LDPDInfo -Aall 重点关注以下几点: Media Error C ...

  3. linux系统无法识别固态硬盘_linux查看硬盘是不是ssd

    lsscsi:看看硬盘的型号,一般都是ssd字样. [6:0:0:0] disk ATA INTEL SSDSC2KB48 0100 /dev/sda [7:0:0:0] disk ATA INTEL ...

  4. Python查询物理机硬盘、主板、BIOS序列号(用于认证Windows设备)

    有些应用场景下我们需要认证设备,对于安装了Windows系统的物理机可以采用WMI获取硬盘.主板.BIOS序列号,从而确认设备的唯一性. 1. 安装依赖库 wmi pip install wmi 2. ...

  5. win7查看硬盘序列号

    #win7硬盘序列号怎么查看 首先按下键盘的win+R组合快捷键:或者是点击开始菜单,在弹出的页面中点击 运行 选项. 然后在出现的运行窗口中输入 cmd 回车. 然后会打开一个黑色的命令行窗口,输入 ...

  6. Linux下查看硬盘序列号、设备序列号、操作系统版本和安装时间、系统启用时间等命令

    Linux下查看硬盘序列号.设备序列号.操作系统版本和安装时间.启用时间等命令 最近由于工作需要查询一些硬盘序列号.设备序列号.操作系统版本和安装时间.系统启用时间等信息.所以对用到的命令进行一下总结 ...

  7. windows下查看硬盘序列号、设备序列号、操作系统版本和安装时间、系统启用时间等命令

    windows下查看硬盘序列号.设备序列号.操作系统版本和安装时间.系统启用时间等命令 最近由于工作需要查询一些硬盘序列号.设备序列号.操作系统版本和安装时间.系统启用时间等信息.所以对用到的命令进行 ...

  8. win10查看设备序列号、硬盘序列号、mac地址

    1. 设备序列号 wmic bios get serialnumber 2. 查看硬盘序列号 wmic diskdrive get serialnumber 3. mac地址 控制面板\网络和 Int ...

  9. Windows系统查看设备序列号及硬盘序列号

    查看设备序列号 打开cmd; 执行:wmic bios get serialnumber 查看硬盘序列号 第一种方法 打开cmd; 执行:wmic diskdrive get model,serial ...

  10. Ubuntu16.04 查看硬盘序列号以及系统版本与安装时间

    由于一些情况,计算机的硬件与系统信息要求统计,由此记录下来在ubuntu系统下的相关指令,省的每次都百度了. 方式一: 不用指令,直接打开system->Administration->D ...

最新文章

  1. 哈啰顺风车成立5亿元“顺风绿色出行基金”
  2. 北京科技大学智能视觉参赛队伍 - 对于比赛总结
  3. 网站推广期间如何做好用户体验中的交互体验设计?
  4. 数据可视化,带给你的惊艳并不止这一点!
  5. Eclipse --Type /com.xx.app/gen already exists but is not a source folde解决方案
  6. pb11 打印 自定义纸张_pb自定义纸张(连续走纸)
  7. C++ 输出单个字符
  8. subtext3php,sublime text3怎么快速查找和替换?快捷键是什么
  9. 许晴×××汤的营养价值
  10. 执行Linux脚本出错,出现No Such file or directory异常
  11. 汉诺塔问题(三柱及四柱)详解
  12. @PropertySource 解析 yml 配置文件,自定义解析 yaml 工厂类
  13. 【第七篇】Vue实战综合案例
  14. 黑苹果系统发热与续航
  15. 用 ANSYS/LS-DYNA 进行显式动力学仿真计算 (转帖,有修改)
  16. 测试用例入门(一)-如何编写用例标题、前置条件、测试步骤和预期结果?
  17. 学会这样用Excel,你也可以月薪三万!
  18. Pytest如何并发执行自动化脚本
  19. SCX-4521F一体机MAC驱动
  20. python绘制蚊香形_python之turtle画蚊香

热门文章

  1. U盘中了磁碟机病毒怎么办
  2. 分享几款好用的强力数据恢复软件
  3. 2019年最新淘宝联盟淘宝客升高佣规则
  4. Cisco ASA 9.17.1 Full ( bin, ova, qcow2, SPA, vhdx ) 下载 - 思科防火墙
  5. Oracle12C-针对log4j漏洞补丁修复
  6. 安全管家安卓_网速管家安卓5.4版本全面上线,多场景网络体验全面升级
  7. linux mint 图标主题_Ubuntu/Linux Mint 用上仿 Win7/Win8 主题
  8. adb shell wm 命令使用
  9. 用U盘给虚拟机装系统——U深度
  10. Revit二次开发记录