java 硬盘物理序列号_请教高手:java如何读取硬盘的序列号

我在CSDN里面帮你找到了一个。。。

http://topic.csdn.net/t/20060222/19/4571391.html

以下是获取硬盘序列号,CPU道理一样.//Sys.javapublicclassSys{publicstaticnativevoidshowHDSerial();static{System.loadLibrary("Sys");}publicstaticvoidmain(String[]args){showHDSerial();}}1)编译javacSys.java2)生成.h文件javah-jniSys3)打开VC->文件->新建->工程->Win32DLL(这里简写了)4)写入工程名;Sys创建空白工程5)将Sys.h,jni.h添加到工程中(其中jni.h在[JAVA_HOME]\include下).6)创建Sys.cpp文件.文件内容如下://Sys.cpp#include"jni.h"#include#include#include#defineDFP_GET_VERSION0x00074080#defineDFP_SEND_DRIVE_COMMAND0x0007c084#defineDFP_RECEIVE_DRIVE_DATA0x0007c088#pragmapack(1)typedefstruct_GETVERSIONOUTPARAMS{BYTEbVersion;//Binarydriverversion.BYTEbRevision;//Binarydriverrevision.BYTEbReserved;//Notused.BYTEbIDEDeviceMap;//BitmapofIDEdevices.DWORDfCapabilities;//Bitmaskofdrivercapabilities.DWORDdwReserved[4];//Forfutureuse.}GETVERSIONOUTPARAMS,*PGETVERSIONOUTPARAMS,*LPGETVERSIONOUTPARAMS;typedefstruct_IDEREGS{BYTEbFeaturesReg;//UsedforspecifyingSMART"commands".BYTEbSectorCountReg;//IDEsectorcountregisterBYTEbSectorNumberReg;//IDEsectornumberregisterBYTEbCylLowReg;//IDElowordercylindervalueBYTEbCylHighReg;//IDEhighordercylindervalueBYTEbDriveHeadReg;//IDEdrive/headregisterBYTEbCommandReg;//ActualIDEcommand.BYTEbReserved;//reservedforfutureuse.Mustbezero.}IDEREGS,*PIDEREGS,*LPIDEREGS;typedefstruct_SENDCMDINPARAMS{DWORDcBufferSize;//BuffersizeinbytesIDEREGSirDriveRegs;//Structurewithdriveregistervalues.BYTEbDriveNumber;//Physicaldrivenumbertosend//commandto(0,1,2,3).BYTEbReserved[3];//Reservedforfutureexpansion.DWORDdwReserved[4];//Forfutureuse.//BYTEbBuffer[1];//Inputbuffer.}SENDCMDINPARAMS,*PSENDCMDINPARAMS,*LPSENDCMDINPARAMS;typedefstruct_DRIVERSTATUS{BYTEbDriverError;//Errorcodefromdriver,//or0ifnoerror.BYTEbIDEStatus;//ContentsofIDEErrorregister.//OnlyvalidwhenbDriverError//isSMART_IDE_ERROR.BYTEbReserved[2];//Reservedforfutureexpansion.DWORDdwReserved[2];//Reservedforfutureexpansion.}DRIVERSTATUS,*PDRIVERSTATUS,*LPDRIVERSTATUS;typedefstruct_SENDCMDOUTPARAMS{DWORDcBufferSize;//SizeofbBufferinbytesDRIVERSTATUSDriverStatus;//Driverstatusstructure.BYTEbBuffer[512];//Bufferofarbitrarylength//inwhichtostorethedatareadfromthedrive.}SENDCMDOUTPARAMS,*PSENDCMDOUTPARAMS,*LPSENDCMDOUTPARAMS;typedefstruct_IDSECTOR{USHORTwGenConfig;USHORTwNumCyls;USHORTwReserved;USHORTwNumHeads;USHORTwBytesPerTrack;USHORTwBytesPerSector;USHORTwSectorsPerTrack;USHORTwVendorUnique[3];CHARsSerialNumber[20];USHORTwBufferType;USHORTwBufferSize;USHORTwECCSize;CHARsFirmwareRev[8];CHARsModelNumber[40];USHORTwMoreVendorUnique;USHORTwDoubleWordIO;USHORTwCapabilities;USHORTwReserved1;USHORTwPIOTiming;USHORTwDMATiming;USHORTwBS;USHORTwNumCurrentCyls;USHORTwNumCurrentHeads;USHORTwNumCurrentSectorsPerTrack;ULONGulCurrentSectorCapacity;USHORTwMultSectorStuff;ULONGulTotalAddressableSectors;USHORTwSingleWordDMA;USHORTwMultiWordDMA;BYTEbReserved[128];}IDSECTOR,*PIDSECTOR;/*+++Globalvars---*/GETVERSIONOUTPARAMSvers;SENDCMDINPARAMSin;SENDCMDOUTPARAMSout;HANDLEh;DWORDi;BYTEj;VOIDChangeByteOrder(PCHARszString,USHORTuscStrSize){USHORTi;CHARtemp;for(i=0;i>j)){//Wedon'tdetectaATAPIdevice.cout<sModelNumber,40);s[40]=0;ChangeByteOrder(s,40);cout<sFirmwareRev,8);s[8]=0;ChangeByteOrder(s,8);cout<sSerialNumber,20);s[20]=0;ChangeByteOrder(s,20);cout<ulTotalAddressableSectors/2/1024<>j)){//Wedon'tdetectaATAPIdevice.cout<sModelNumber,40);s[40]=0;ChangeByteOrder(s,40);cout<sFirmwareRev,8);s[8]=0;ChangeByteOrder(s,8);cout<sSerialNumber,20);s[20]=0;ChangeByteOrder(s,20);cout<ulTotalAddressableSectors/2/1024<

7)新建Sys.def  文件,内容如下

EXPORTS

Java_Sys_showHDSerial

编译Sys  工程,生成Sys.dll

9)将Sys.dll  拷到Sys.class  同目录下

10)运行

java  Sys

得到如下结果(本人机器)

F:\>java  Sys

Module  Number:SAMSUNG  SP0802N

Firmware  rev:TK100-28

Serial  Number:            S00JJ50Y418303

Capacity:76293M

参与评论 您还未登录,请先 登录 后发表或查看评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:游动-白 设计师:我叫白小胖 返回首页

打赏作者

兔小白王子

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值