用VB源程序读取硬盘物理序列号
硬盘物理序列号的得到方法_hemfanings
网址或邮箱: (选填)
内 容:插入表情▼ 闪光字
验证码: 请点击后输入四位验证码,字母不区分大小写
看不清?
取消回复", , 48)
For Each objItem In colItems
MsgValue = MsgValue & vbCrLf & "主板=" & objItem.SerialNumber
Next
MsgValue = MsgValue & vbCrLf & "硬盘 = " & objItem.SerialNumber
Next
'获取主板序列号
Set colItems = objWMIService.ExecQuery("Select * from
'获取CPU ID
Set colItems = objWMIService.ExecQuery("Select * from
Win32_Processor", , 48)
For Each objItem In colItems
•DELPHI中读取硬盘的物理序列号 •C++ 硬盘物理序列号
•获取硬盘物理序列号 •取得硬盘物理和逻辑序列号
•VB 利用硬盘物理序列号进行软件... •初步实现系统级拦截应用程序取硬...
48)
For Each objItem In colItems
MsgValue = MsgValue & vbCrLf & "BIOS= " & objItem.SerialNumber
怎样用vc获取硬盘物理序列号
#pragma once#ifndef __AFXWIN_H__#error include 'stdafx.h' before including this file for PCH #endif#include "resource.h"// 主符号// CgetinfoApp:// 有关此类的实现,请参阅 getinfo.cpp//class CgetinfoApp : public CWinApp{public:CgetinfoApp();// 重写public:virtual BOOL InitInstance();// 实现DECLARE_MESSAGE_MAP()};extern CgetinfoApp theApp;// getinfoDlg.h : 头文件//#pragma once// CgetinfoDlg 对话框class CgetinfoDlg : public CDialog{// 构造public:CgetinfoDlg(CWnd* pParent = NULL);// 标准构造函数// 对话框数据enum { IDD = IDD_GETINFO_DIALOG };virtual void DoDataExchange(CDataExchange* pDX);// DDX/DDV 支持// 实现protected:HICON m_hIcon;// 生成的消息映射函数virtual BOOL OnInitDialog();afx_msg void OnSysCommand(UINT nID, LPARAM lParam);afx_msg void OnPaint();afx_msg HCURSOR OnQueryDragIcon();DECLARE_MESSAGE_MAP()public:afx_msg void OnBnClickedOk();};//{{NO_DEPENDENCIES}}// Microsoft Visual C++ generated include file.// Used by getinfo.RC//#define IDR_MAINFRAME128#define IDM_ABOUTBOX0x0010#define IDD_ABOUTBOX100#define IDS_ABOUTBOX101#define IDD_GETINFO_DIALOG102#define IDR_MANIFESTCREATEPROCESS_MANIFEST_RESOURCE_ID// 新对象的下一组默认值//#ifdef APSTUDIO_INVOKED#ifndef APSTUDIO_READONLY_SYMBOLS#define _APS_NEXT_RESOURCE_VALUE129#define _APS_NEXT_CONTROL_VALUE1000#define _APS_NEXT_SYMED_VALUE101#define _APS_NEXT_COMMAND_VALUE32771#endif#endif// stdafx.h : 标准系统包含文件的包含文件,// 或是经常使用但不常更改的// 项目特定的包含文件#ifndef VC_EXTRALEAN#define VC_EXTRALEAN// 从 Windows 标头中排除不常使用的资料#endif// 如果您必须使用下列所指定的平台之前的平台,则修改下面的定义。
利用硬盘卷序列号实现对VB软件注册的解决方案
图 1图 2的详细实现过程。
关键词: 硬盘卷序列号; 软件注册; VB 中图分类号: TP 39 文献标识码: A文章编号: 1009- 3044(2006)35- 0092- 02A S o lution of VB S o ftwa r e R e g is t e r Us i n g Ha rd dis k V olume S e ria l Nu m b e rDU Xuan(S chool of Information Engineering, Jiaxing University, Jiaxing 314001,C hina)Ab s tra ct:T o get user computer harddisk volume serial number as machine ID in the VB application sof tware,T o generate software register code after encryption.As the harddisk volume serial number is alone, S oftware register code provided is only er will register their VB ap- plication sof tware using the software register code.T his text introduce det ailed implementation process that user regis ter their VB application s oft- ware using the software register based on harddisk volume serial number.Ke y wo rd s :Harddisk Volume S erial N u mber; S oftware R e gister; VB1 引言现在有些网站为用户提供软件下载试用功能, 用户可以随意 免费下载一些自己感兴趣的应用软件来使用, 其中有一些软件在 功能上有所限制, 如果需要使用其全部功能, 可以通过向软件开发 者购买注册码的方式, 通过软件中提供的注册码验证机制实现软 件功能的开放。
硬盘序列号获取的实际操作
硬盘序列号是基本常识,然后我就学习及深入的研究硬盘序列号,在这里和大家一起探讨硬盘序列号的使用方法,希望对大家有用。
要获取硬盘序列号,需要访问注册表.实际操作如下,建立一个新的窗体,在上面添加一个标签Label1,一个按钮command1,实现:按下按钮,在标签上显示硬盘序列号.
代码:
namespace monPrj {
#region how use this?
/*
string sVol = getvol.GetVolOf("C");
*/
#endregion
public class getvol{
[DllImport("kernel32.dll")]
End Type
Private Sub Command1_Click()
Dim x As DRIVER_INFO_OK
Dim i As Long
If IsWinNT = 1 Then
i = ReadPhysicalDriveInNT(ByVal 0, ByVal VarPtr(x), ByVal 256)
Private Declare Function ReadPhysicalDriveInNT Lib "DiskID.DLL" (driveID As Long, buffer As Long, bufLen As Long) As Long
Private Type DRIVER_INFO_OK
SerialNum: LongInt;
VolLabel: Packed Array [0..10] of Char;
FileSysType: Packed Array [0..7] of Char;
VB利用GetObject(WinMgmts)获取系统信息
For Each wbemObject In wbemObjectSet
WScript.Echo "物理内存 (MB): " & CInt(wbemObject.TotalPhysicalMemory/1024)
用WMI对象列出系统所有进程:
----Instance.vbs---- 程序代Βιβλιοθήκη Dim WMI,objs
Set WMI = GetObject("WinMgmts:")
Set objs = WMI.InstancesOf("Win32_Process")
For Each obj In objs
next
msgbox infor
CPU的序列号:
---CPUID.vbs---
程序代码
Dim cpuInfo
cpuInfo = ""
set moc = GetObject("Winmgmts:").InstancesOf("Win32_Processor")
for each mo in moc
for each mo in moc
HDid = mo.Model
msgbox "硬盘型号为:" & HDid
next
网卡MAC物理地址:
---MACAddress.vbs---
程序代码
Dim mc
使用API取得硬盘的信息
技巧1使用API取得硬盘信息在VBA中可以使用API函数取得逻辑盘序列号和唯一的物理系列号,如下面的代码所示。
Private ConstMAX_IDE_D RIVES As Long = 4Private Const READ_ATTR IBUTE_BUF FER_SIZE As Long= 512Private Const IDENTIFY_ BUFFER_SI ZE As Long= 512Private Const READ_THRE SHOLD_BUF FER_SIZE As Long= 512Private ConstDFP_GET_V ERSION As Long= &H74080Private ConstDFP_SEND_ DRIVE_COM MAND As Long= &H7C084Private ConstDFP_RECEI VE_DRIVE_ DATA As Long= &H7C088……代码略,详见附件'取得硬盘信息:型号/物理系列号(唯一)Function GetHardDi skInfo(Op tional ByVal numDisk As eumDiskNo = hdPrimary Master, Optional ByVal numType As eumInfoTy pe= hdOnlySN) As StringIf GetDiskIn fo(numDis k)=1 ThenDim pSerialNu mber As String, pModelNum ber As StringpSerialNu mber= StrConv(m _DiskInfo .sSerialN umber, vbUnicode ) pModelNum ber= StrConv(m _DiskInfo .sModelNu mber, vbUnicode )Select Case numType Case hdOnlyMod el'仅型号GetHardDi skInfo= Trim(pMod elNumber) Case hdOnlySN '仅系列号GetHardDi skInfo= Trim(pSer ialNumber )Case Else '型号,系列号GetHardDi skInfo= Trim(pMod elNumber) &","& Trim(pSer ialNumber )EndSelectEnd IfEnd Function 代码解析;使用API函数取得逻辑盘序列号和唯一的硬盘物理系列号,其中GetDiskVo lume函数过程取得逻辑盘序列号,GetHardDi skInfo函数过程取得唯一的硬盘物理系列号。
vb_取得硬盘物理编号
Private Declare Function CreateFile Lib "kernel32" _
Alias "CreateFileA" (ByVal lpFileName As String, _
ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) _
As Long
Private Const CREATE_NEW = 1
Private Const GENERIC_READ = &H80000000
x As Byte
fCapabilities As Long
dwReserved(4) As Long
End Type
Private Type TIDEREGS
bFeaturesReg As Byte
bSectorCountReg As Byte
Private Type OVERLAPPED
Internal As Long
InternalHigh As Long
offset As Long
OffsetHigh As Long
hEvent As Long
End Type
ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, _
ByVal lpSecurityAttributes As Long, _
ByVal dwCreationDisposition As Long, _
读取本机硬件信息的VBA代码
读取本机硬件信息的VBA代码今天被朋友问到,如何在VB或者VBA代码中读取诸如硬盘或者CPU等硬件设备的序列号这一类信息。
我写了一个范例如下1. 在我的机器上运行的效果。
我这个例子读取了四部分信息(CPU,物理硬盘,逻辑磁盘,网卡)2.代码如下。
代码的原理是使用WMI接口。
需要管理员权限才能执行该代码Private Type OSVERSIONINFOdwOSVersionInfoSize As LongdwMajorVersion As LongdwMinorVersion As LongdwBuildNumber As LongdwPlatformId As LongszCSDVersion As String * 128 ' Maintenance string for PSS usage End TypePrivate Declare Function GetVersionEx Lib 'kernel32' Alias 'GetVersionExA' (lpVersionInformation As OSVERSIONINFO) As LongPrivate Declare Function GetComputerName Lib 'kernel32' Alias 'GetComputerNameA' (ByVal lpBuffer As String, nSize As Long) As LongPrivate Const VER_PLATFORM_WIN32_NT = 2Private Const VER_PLATFORM_WIN32_WINDOWS = 1Private Const VER_PLATFORM_WIN32s = 0'''这个范例程序是读取CPU,物理硬盘,逻辑磁盘,和网卡的有关序列号的'''作者:陈希章'''时间:2009年6月2日Sub Test()Dim len5 As Long, aa As LongDim cmprName As StringDim osver As OSVERSIONINFO'取得Computer NamecmprName = String(255, 0)len5 = 256aa = GetComputerName(cmprName, len5)cmprName = Left(cmprName, InStr(1, cmprName, Chr(0)) - 1)Computer = cmprName '取得CPU端口号ActiveCell.Worksheet.Cells.ClearDim rng As RangeSet rng = Range('B7')rng.Font.Bold = Truerng.Value = 'CPU'Set rng = rng.Offset(1)Set CPUs = GetObject('winmgmts:{impersonationLevel=impersonate}!\\' & Computer & '\root\cimv2').ExecQuery('select * from Win32_Processor') For Each mycpu In CPUsrng.Value = mycpu.processoridSet rng = rng.Offset(1)Nextrng.Value = 'Hard Disk'rng.Offset(, 1).Value = 'Media Type'rng.Resize(, 2).Font.Bold = TrueSet rng = rng.Offset(1)Set disks = GetObject('winmgmts:{impersonationLevel=impersonate}!\\' & Computer & '\root\cimv2').ExecQuery('select * from Win32_DiskDrive') For Each disk In disksrng.Value = disk.pnpdeviceidrng.Offset(, 1).Value = disk.mediatypeSet rng = rng.Offset(1)NextSet hds = GetObject('winmgmts:{impersonationLevel=impersonate}!\\' & Computer & '\root\cimv2').ExecQuery('select * from Win32_LogicalDisk') rng.Value = 'Logic Disk Caption'rng.Offset(, 1).Value = 'VolumeSerialNumber'rng.Resize(, 2).Font.Bold = TrueSet rng = rng.Offset(1)For Each hd In hdsrng.Value = hd.Captionrng.Offset(, 1).Value = hd.VolumeSerialNumberSet rng = rng.Offset(1)NextSet networks = GetObject('winmgmts:{impersonationLevel=impersonate}!\\' & Computer & '\root\cimv2').ExecQuery('select * from Win32_NetworkAdapt er')rng.Value = 'Caption'rng.Offset(, 1).Value = 'MAC Address'rng.Offset(, 2).Value = 'PNPDeviceID'rng.Resize(, 3).Font.Bold = TrueSet rng = rng.Offset(1)For Each network In networksrng.Value = network.Captionrng.Offset(, 1).Value = network.macaddressrng.Offset(, 2).Value = network.pnpdeviceidSet rng = rng.Offset(1)NextEnd Sub。
vb获取硬盘序列号利用硬盘序列号计算软件注册码-vb
vb获取硬盘序列号:利用硬盘序列号计算软件注册码-vb教程疯狂代码 / ĵ:http://VisualBasic/Article15611.html盘序列号计算软件注册码。
在模块中加入下列声明:Public Declare Function GetVolumeInformation Lib \"kernel32\" _Alias \"GetVolumeInformationA\" (ByVal lpRootPathName As String, _ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, _lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, _lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, _ByVal nFileSystemNameSize As Long) As Long´得到某一磁盘分区的信息,如C:窗体代码如下:Option ExplicitPrivate Regid, Localid As LongPrivate Sub CmdLocalID_Click()´根据C盘序列号得到原IDDim Driver, VolName, Fsys As StringDim volNumber, MCM, FSF As LongDriver = \"c:\\\"Dim res As Longres = GetVolumeInformation(Driver, VolName, 127, volNumber, MCM, FSF, Fsys, 127)´volNumber是C盘序列号Localid = volNumber / 2 + 123456789Text1.Text = LocalidEnd SubPrivate Sub CmdRegID_Click()´根据原ID算出注册IDIf IsNumeric(Text1.Text) ThenRegid = CLng(Text1.Text) / 4 * 3 + 987654321Else´errorEnd IfText2.Text = RegidEnd SubPrivate Sub CmndCheckID_Click()´验证注册IDDim Driver, VolName, Fsys As StringDim volNumber, MCM, FSF As LongDriver = \"c:\\\"Dim res As Longres = GetVolumeInformation(Driver, VolName, 127, volNumber, MCM, FSF, Fsys, 127)Dim Tid As LongTid = volNumber / 2 + 123456789If Regid = Tid / 4 * 3 + 987654321 ThenMsgBox \"正确!\"ElseMsgBox \"错误!\"End IfEnd Sub为便于演示,我在窗体上用了两个文本框三个按钮,请根据情况灵活使用,可以在用户端算出原ID,发给你,你算出注册ID再发给用户,验证当然是在用户端啦。
VB程式如何取得 硬碟 及 主机板 序号
如何取得硬碟及主機板序號VB使用WMI ( Windows Management Instrumentation ) 來取得<< >> 寫法1Imports System.Runtime.InteropServicesPublic Class Form1Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load MessageBox.Show("硬碟序號: " & Get_PscDrv_SNo(0) & _ControlChars.CrLf & ControlChars.CrLf & _"主機板序號: " & Get_MB_SNo())End Sub' 取得硬碟序號( 實體磁碟)' 當有多顆硬碟時, 可調傳入參數為1 , 2 .. 依此類推Private Function Get_PscDrv_SNo(ByVal DrvIdx As Byte) As StringDim WMI As Object = GetObject("winmgmts:") ' 取得WMI 物件' GetObject : 傳回COM 元件所提供物件的參考。
Dim strCls As String = "Win32_PhysicalMedia"' WMI 類別Dim strKey As String = strCls & ".Tag=""\\\\.\\PHYSICALDRIVE" & DrvIdx & """"Return WMI.InstancesOf(strCls)(strKey).SerialNumber.ToString.Trim ' 取得SerialNumber 屬性Marshal.ReleaseComObject(WMI) ' 釋放Com 物件所使用的資源End Function' 取得主機板序號Private Function Get_MB_SNo() As StringDim WMI As Object = GetObject("winmgmts:") ' 取得WMI 物件' GetObject : 傳回COM 元件所提供物件的參考。
硬盘参数读取程序 - 硬盘型号、容量、序列号、固件版本等for Windows 98MENT2000XP
文件示意图://---------------------------------------------------------------------------#include <vcl.h>#pragma hdrstop//--------------------------------------------------------------------------- USEFORM("UnitHdDisk.cpp", FormHdParams);//--------------------------------------------------------------------------- WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int){try{Application->Initialize();Application->CreateForm(__classid(TFormHdParams), &FormHdParams);Application->Run();}catch (Exception &exception){Application->ShowException(&exception);}catch (...){try{throw Exception("");}catch (Exception &exception){Application->ShowException(&exception);}}return 0;}//---------------------------------------------------------------------------/*-------------------------------------------------------------------------*\||| IDE 硬盘参数读取程序|| ~~~~~~~~~~~~~~~~~~~~ || Copyright (C) 1997-2003, Victor Chen || Email: victor@ || Homepage: |||\*-------------------------------------------------------------------------*/ #include "ide_disk.h"#pragma link "WinIo_bc.lib"//--------------------------------------------------------------------------- unsigned char inportb(unsigned short p){unsigned long v = 0;GetPortVal(p, &v, 1);return v;}//--------------------------------------------------------------------------- unsigned short inportw(unsigned short p){unsigned long v = 0;GetPortVal(p, &v, 2);return v;}//--------------------------------------------------------------------------- unsigned long inportd(unsigned short p){unsigned long v = 0;GetPortVal(p, &v, 4);return v;}//---------------------------------------------------------------------------void outportb(unsigned short p, unsigned char v){SetPortVal(p,v,1);}//---------------------------------------------------------------------------void outportw(unsigned short p, unsigned short v){SetPortVal(p,v,2);}//---------------------------------------------------------------------------void outportd(unsigned short p, unsigned long v){SetPortVal(p,v,4);}//=================================================== ========================char DetectHDD(unsigned long BasePort) //bit 0: HDD-0, Bit 1: HDD-1 {int HD_No, HD_Detected=0, i, f;unsigned char HD_Selection[2]={0xa0,0xb0}; // C:1010 0000, D:1011 0000for(HD_No=0; HD_No<=1; HD_No++){f=0;for(i=0;i<300;i++) //Get HDD Status, wait until HDD not busy{if((inportb(BasePort+7)&0x80)==0){f=1;break;}Sleep(2);}if(!f)continue;outportb(BasePort+6, HD_Selection[HD_No]); //0# HDD Drive/Head Registeroutportb(BasePort+7, 0x10); //0# HDD Status, Head back to Track 0f=0;for(i=0;i<300;i++) //Get HDD Status, wait until HDD not busy{if((inportb(BasePort+7)&0x80)==0){f=1;break;}Sleep(2);}if(!f)continue;if(inportb(BasePort+7)==0x50) // HDD ready: 0101 0000{HD_Detected|=(1<<HD_No);}}return HD_Detected;}//---------------------------------------------------------------------------int GetHDDInfo(TIDE_ID_Inf *Info, char DriveNo, unsigned intBasePort) //DriveNo ... 0:C, 1:D{unsigned int i=0;int Err=0;if(DriveNo==0)outportb(BasePort+6, 0xa0); //select drive C:elseoutportb(BasePort+6, 0xb0); //select drive D:outportb(BasePort+7, 0xec); //read HDD Infowhile(inportb(BasePort+7)!=0x58) //0# HDD Status, wait for R/W ready 0101 0000{if(i>=300){Err=1;break;}Sleep(2);i++;}if(!Err)for(i=0;i<=255;i++)Info->w[i]=inportw(BasePort);return Err;}//--------------------------------------------------------------------------- void WordToStr(unsigned char *s, unsigned short *w, int n) {int i;for(i=0; i<n; i++){s[i*2] = w[i]>>8;s[i*2+1] = w[i]&0x00ff;}s[i*2]=0;}//---------------------------------------------------------------------------/*-------------------------------------------------------------------------*\||| IDE 硬盘参数读取程序|| ~~~~~~~~~~~~~~~~~~~~ || Copyright (C) 1997-2003, Victor Chen || Email: victor@ || Homepage: |||\*-------------------------------------------------------------------------*/#ifndef _IDE_DISK_H_YBCHEN_#define _IDE_DISK_H_YBCHEN_//-------------------------------------------------------------------------//#include <vcl.h>#include "WinIo.h"//-------------------------------------------------------------------------//enum TIdePortAddrItem{IDE1_Port = 0x1f0, //primary IDE ControllerIDE2_Port = 0x170, //secondary IDE ControllerIDE3_Port = 0x1e8, //Tertiary IDE ControllerIDE4_Port = 0x168, //Quaternary IDE Controller};//--------------------- IDE_ID_Inf.Capabs (Offset 62H) --------------------// enum TIdeInfCapabsItem{IDE_TIM_DTA = 0x2000, //13 Standby Timer values used according to ATA standardIDE_IOR_Spp = 0x0800, //11 IORDY supportedIDE_DIS_IOR = 0x0400, //10 device can disable use of IORDY IDE_LBA_Spp = 0x0200, // 9 LBA mode supportedIDE_DMA_Spp = 0x0100, // 8 DMA supported};//-------------------------------------------------------------------------//#pragma pack(push,1)typedef union{unsigned short w[256];struct{unsigned short GenCfg; // 00h WORD general configurationunsigned short L_Cyln; // 02h WORD number of logical cylindersunsigned short Res_00; // 04h WORD reservedunsigned short L_Head; // 06h WORD number of logical headsunsigned short VndSp0; // 08h WORD vendor-specific unsigned short VndSp1; // 0Ah WORD vendor-specific unsigned short L_Sect; // 0Ch WORD number of logical sectorsunsigned short VndSp2; // 0Eh WORD vendor-specific unsigned short VndSp3; // 10h WORD vendor-specific unsigned short VndSp4; // 12h WORD vendor-specific unsigned short Serial[10]; // 14h 10 WORDs serial number// no serial number if first word is 0000h// else blank-padded ASCII serial numberunsigned short CnType; // 28h WORD vendor-specific[controller type]unsigned short BufNum; // 2Ah WORD vendor-specific// [controller buf.size in 512-byte sectors]unsigned short ECCByt; // 2Ch WORD number of vendor-specific(usually// ECC) bytes on Read/Write Longunsigned short Revisn[4]; // 2Eh 4 WORDs firmware revision// no revision number if first word is 0000h// else blank-padded ASCII revision numberunsigned short nModel[20]; // 36h 20 WORDs model number// no model number if first word is 0000h// else blank-padded ASCII model stringunsigned short Multip; // 5Eh WORD read/write multiple support// bits 7-0:maximum number of sectors per// block supported,// 00h if read/write multiple not supportedunsigned short Res_01; // 60h WORD reserved (0)// able to do doubleword transfers if// nonzero ???unsigned short Capabs; // 62h WORD capabilities, bit 9: LBA supportedunsigned short Securi; // 64h WORD security mode// bit 15: security-mode feature set supported// bits 14-8: maximum number of passwords supportedunsigned short PIOTim; // 66h WORD PIO data transfer cycle timingunsigned short DMATim; // 68h WORD single-word DMA data transfer cycle timing//========================================================================unsigned short FldVal; // 6Ah WORD field validity// bit 0: offsets 6Ch-73h valid// bit 1: offsets 80h-8Dh valid//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=unsigned short CLCyln; // 6Ch WORD logical cylinders in current translation modeunsigned short CLHead; // 6Eh WORD logical heads in current translation modeunsigned short CLSect; // 70h WORD logical sectors per track in current translation modeunsigned long CLCapa; // 72h 2 WORDs current capacity in sectors (excluding device-specific uses)//------------------------------------------------------------------------unsigned short McSect; // 76h WORD multiple-sector count for read/write multiple commandunsigned long LBASec; // 78h 2 WORDs total number of user-addressable sectors (LBA mode), 00000000h if LBA mode notsupportedunsigned short SW_DMA; // 7Ch WORD single-word DMA transfer modes// low byte is bitmap of supported modes (bit 0 = mode 0, etc.)// high bytes is bitmap of active mode (bit 8 = mode 0, etc.)unsigned short MW_DMA; // 7Eh WORD multiword DMA transfer// low byte is bitmap of supported modes (bit 0 = mode 0, etc.)// high bytes is bitmap of active mode (bit 8 = mode 0, etc.)//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=unsigned short FC_PIO; // 80h WORD supported flow control PIO transfer modesunsigned short MinDTm; // 82h WORD minimum multiword DMA transfer cycle timeunsigned short RcmDTm; // 84h WORD recommended multiword DMA cycle timeunsigned short MinNTm; // 86h WORD minimum non-flow-control PIO transfer cycle timeunsigned short MinPTm; // 88h WORD minimum PIO transfer cycle time with IORDYunsigned short Res_02[2]; // 8Ah 2 WORDs reserved for future PIO modes (0)//------------------------------------------------------------------------unsigned short Res_03[57]; // 8Eh 57 WORDs reserved (0)unsigned short VndSp5[32]; //100h 32 WORDs vendor-specificunsigned short Res_04[95]; //140h 95 WORDs reserved (0)//------------------------------------------------------------------------unsigned short ChkSum; //1FE WORD Checksum and signature(0xa5)};} TIDE_ID_Inf; //Tt: 512 = 0x140+96*2#pragma pack(pop)//-------------------------------------------------------------------------//extern char DetectHDD(unsigned long BasePort); //bit 0: HDD-0, Bit 1: HDD-1extern int GetHDDInfo(TIDE_ID_Inf *Info, char DriveNo, unsigned int BasePort); //DriveNo ... 0:C, 1:Dextern void WordToStr(unsigned char *s, unsigned short *w, int n);//-------------------------------------------------------------------------//#endif//-------------------------------------------------------------------------///*-------------------------------------------------------------------------*\||| IDE 硬盘参数读取程序|| ~~~~~~~~~~~~~~~~~~~~ || Copyright (C) 1997-2003, Victor Chen || Email: victor@ || Homepage: |||\*-------------------------------------------------------------------------*/#include <vcl.h>#pragma hdrstop#include "UnitHdDisk.h"#include "IDE_DISK.H"//---------------------------------------------------------------------------#pragma package(smart_init)#pragma resource "*.dfm"TFormHdParams *FormHdParams;//---------------------------------------------------------------------------__fastcall TFormHdParams::TFormHdParams(TComponent* Owner) : TForm(Owner){Memo1->Text = "读取硬盘参数\r\nCopyright (C) Victor Chen\r\nHomepage: /\r\n\r\n";Memo1->Lines->Add("按“硬盘参数”按钮读取硬盘参数\r\n==============================================");bWinIoInitOK = InitializeWinIo();if(!bWinIoInitOK){Application->MessageBox("不能装载WinIO 程序!","错误信息",MB_OK|MB_ICONSTOP);Application->Terminate();}}//---------------------------------------------------------------------------__fastcall TFormHdParams::~TFormHdParams(){if(bWinIoInitOK)ShutdownWinIo();}//---------------------------------------------------------------------------void __fastcall TFormHdParams::ButtonHdParamsClick(TObject *Sender){TIdePortAddrItem ControllerPorts[] = {IDE1_Port, IDE2_Port}; AnsiString ControllerNames[] = {"IDE0", "IDE1"};char *HardDiskNames[] = {"主盘", "从盘"};char HardDiskDetected; //bit 0:master, bit 1:slaveTIDE_ID_Inf IDE_Info;char Str[128];for(int i=0; i<2; i++){Memo1->Lines->Add("正在检测: " + ControllerNames[i] + ", 可能需要几秒钟时间, 请稍候……");HardDiskDetected=DetectHDD(ControllerPorts[i]);switch(HardDiskDetected&3){case 0: Memo1->Lines->Add("没检测到硬盘"); break;case 1: Memo1->Lines->Add("检测到主盘"); break;case 2: Memo1->Lines->Add("检测到从盘"); break;case 3: Memo1->Lines->Add("检测到主盘和从盘"); break;}for(int k=0;k<2;k++) //primary/slave diskif(HardDiskDetected & (1<<k)){Memo1->Lines->Add("=================================== ===========");Memo1->Lines->Add(ControllerNames[i] + HardDiskNames[k]+ ":");Memo1->Lines->Add("----------------------------------------------");GetHDDInfo(&IDE_Info, k, ControllerPorts[i]);//---------- model, serial number & firmware revisionWordToStr(Str, IDE_Info.nModel, 20);Memo1->Lines->Add("型号: " + AnsiString(Str).Trim());WordToStr(Str, IDE_Info.Serial, 10);Memo1->Lines->Add("序列号: " + AnsiString(Str).Trim());WordToStr(Str, IDE_Info.Revisn, 4);Memo1->Lines->Add("固件版本: " + AnsiString(Str).Trim());//---------- capacityunsigned long LbaCap = IDE_Info.LBASec/2048, NomCap = ((unsignedlong)(IDE_Info.L_Cyln)*(IDE_Info.L_Head)*(IDE_Info.L_Sect))/2048;Memo1->Lines->Add("容量: " + AnsiString().sprintf("%lu Mb",LbaCap>NomCap?LbaCap:NomCap));//---- output hard disk normal informationMemo1->Lines->Add(AnsiString().sprintf("柱面数: %u", IDE_Info.L_Cyln));Memo1->Lines->Add(AnsiString().sprintf("磁头数: %u", IDE_Info.L_Head));Memo1->Lines->Add(AnsiString().sprintf("扇区数: %u", IDE_Info.L_Sect));Memo1->Lines->Add(AnsiString().sprintf("缓存容量: %u kb", IDE_Info.BufNum>>1));Memo1->Lines->Add(AnsiString().sprintf("ECC 字节: %u bytes", IDE_Info.ECCByt));Memo1->Lines->Add(AnsiString().sprintf("LBA 支持: %s", (IDE_Info.Capabs&IDE_LBA_Spp)?"是":"否"));}Memo1->Lines->Add("=================================== ===========");}}//---------------------------------------------------------------------------void __fastcall TFormHdParams::ButtonExitClick(TObject *Sender) {Close();}//---------------------------------------------------------------------------//---------------------------------------------------------------------------#ifndef UnitHdDiskH#define UnitHdDiskH//--------------------------------------------------------------------------- #include <Classes.hpp>#include <Controls.hpp>#include <StdCtrls.hpp>#include <Forms.hpp>#include <ExtCtrls.hpp>//--------------------------------------------------------------------------- class TFormHdParams : public TForm{__published: // IDE-managed Components TMemo *Memo1;TPanel *Panel1;TButton *ButtonHdParams;TButton *ButtonExit;void __fastcall ButtonExitClick(TObject *Sender);void __fastcall ButtonHdParamsClick(TObject *Sender); private: // User declarationsbool bWinIoInitOK;public: // User declarations__fastcall TFormHdParams(TComponent* Owner);__fastcall ~TFormHdParams();};//--------------------------------------------------------------------------- extern PACKAGE TFormHdParams *FormHdParams;//--------------------------------------------------------------------------- #endif#ifndef WINIO_H#define WINIO_H#ifdef WINIO_DLL#define WINIO_API _declspec(dllexport)#else#define WINIO_API _declspec(dllimport)#endifextern "C"{WINIO_API bool _stdcall InitializeWinIo();WINIO_API void _stdcall ShutdownWinIo();WINIO_API PBYTE _stdcall MapPhysToLin(PBYTE pbPhysAddr, DWORD dwPhysSize, HANDLE *pPhysicalMemoryHandle);WINIO_API bool _stdcall UnmapPhysicalMemory(HANDLE PhysicalMemoryHandle, PBYTE pbLinAddr);WINIO_API bool _stdcall GetPhysLong(PBYTE pbPhysAddr, PDWORD pdwPhysVal);WINIO_API bool _stdcall SetPhysLong(PBYTE pbPhysAddr, DWORD dwPhysVal);WINIO_API bool _stdcall GetPortVal(WORD wPortAddr, PDWORD pdwPortVal, BYTE bSize);WINIO_API bool _stdcall SetPortVal(WORD wPortAddr, DWORDdwPortVal, BYTE bSize);WINIO_API bool _stdcall InstallWinIoDriver(PSTR pszWinIoDriverPath, bool IsDemandLoaded = false);WINIO_API bool _stdcall RemoveWinIoDriver();}extern bool IsNT;extern HANDLE hDriver;extern bool IsWinIoInitialized;bool _stdcall StartWinIoDriver();bool _stdcall StopWinIoDriver();#endif。
获取硬盘物理序列号
scip.irDriveRegs.bFeaturesReg=0; scip.irDriveRegs.bSectorCountReg=1; scip.irDriveRegs.bSectorNumberReg=1; scip.irDriveRegs.bCylLowReg=0; scip.irDriveRegs.bCylHighReg=0; scip.irDriveRegs.bDriveHeadReg=0xA0 | (((BYTE) drive & 1) << 4); scip.irDriveRegs.bCommandReg=bIDCmd; scip.bDriveNumber=(BYTE) drive; scip.cBufferSize=IDENTIFY_BUFFER_SIZE; if (!DeviceIoControl(drive, DFP_RECEIVE_DRIVE_DATA, &scip, sizeof (SENDCMDINPARAMS) - 1,
获取硬盘物理序列号 最近才做完了这个获取 IDE 硬盘物理序列号的程序。声明一下,这个程序是我根据 Lynn McGuire 的那个 DiskID32 的源代码做了些自以为是的改动得到的,只能在 NT 平台下获 得第一块 IDE 硬盘的物理序列号。同时,这个程序用到了不少未公开的 Windows 的结构 和常量......
sizeof (VersionParams), &cbBytesReturned, NULL)) {
// 错误处理 return ; } if (VersionParams.bIDEDeviceMap<=0) { // 错误处理 return ; } BYTE bIDCmd = 0; SENDCMDINPARAMS scip; bIDCmd = (VersionParams.bIDEDeviceMap >> 0 & 0x10) ? IDE_ATAPI_IDENTIFY : IDE_ATA_IDENTIFY; memset (&scip, 0, sizeof(scip)); memset (IdOutCmd, 0, sizeof(IdOutCmd)); scip.cBufferSize=IDENTIFY_BUFFER_SIZE;
VB6编程中如何获取硬盘分区信息
也许你并不了解硬盘分区信息应该包括些什么,但如果你曾经对硬盘分过区,你或许对此有所了解,在此为各位介绍一个用VB编写的获取硬盘分区信息的程序。
在这个程序中,它将详细地告诉你:你的硬盘总容量、分过几个区、每个区的总容量、及现在剩余的可用容量、硬盘分区表为几位(即是FAT32还是FAT16),每个分区是几个字节……怎么样?够完整详细了吧!好的,就让我们一起来看一下吧:首先做准备工作:在FORM1上新建二个LABEL(LABEL1和LABEL2)一个COMMAND1命令按钮。
然后输入以下代码:Private Declare Function GetDriveType Libkernel32“Alias "GetDriveTypeA(ByVal nDrive As String) As LongPrivate Declare Function GetDiskFreeSpace Lib“kernel32" Alias“GetDiskFreeSpaceA" (ByVal lpRootPathName As String, lpSectorsPerCluster As Long, lpBytesPerSector As Long, lpNumberOfFreeClusters As Long, lpTtoalNumberOfClusters As Long) As LongPrivate Const DRIVE_FIXED = 3Private Sub Form_Load() '作初始化设置COMMAND1.Caption = “测试硬盘"Form1.Caption = “测试硬盘程序"Label1.WordWrap = TrueLabel1.Captio n = “"Label2.WordWrap = TrueLabel2.Caption = “"End SubPrivate Sub COMMAND1_Click()Dim DriveNum As IntegerDim TempDrive As StringDim X As LongFor DriveNum = 97 To 122 Step 1 '检测从A-Z(盘符)TempDrive = GetDriveType(Chr(DriveNum) &“:\")Select Case TempDrive '如是3则表示是硬盘,测试你有几个盘Case 3: X = GetDiskSpace(Chr(DriveNum)) '调用子程序End SelectNext DriveNumEnd SubPublic Function GetDiskSpace(DrivePath As String)Dim Drive As StringDim SectorsPerCluster As LongDim BytesPerSector As LongDim NumberOfFreeClusters As LongDim TotalClusters As LongDim Check As IntegerDim DiskSpaceDim diskTotalStatic AllDiskTotal As LongStatic NUM As IntegerNUM = NUM +1 '分几个区的计算Drive = Left(Trim(DrivePath), 1) &“:\"Check = GetDiskFreeSpace(Drive, SectorsPerCluster, BytesPerSector, NumberOfFreeClusters, TotalClusters)If Check <> 0 ThenDiskSpace = SectorsPerCluster *BytesPerSector *NumberOfFreeClusters'这是一个分区磁盘剩余空间的计算公式DiskSpace = Format$(DiskSpace, “###,###") '以规定格式显示,如732,324,231 diskTotal = SectorsPerCluster *BytesPerSector *TotalClusters'这是一个分区磁盘总容量的计算公式diskTotal = Format$(diskTotal, “###,###")AllDiskTotal = AllDiskTotal +diskTotal '整个硬盘的总容量Label1.Caption =“你的硬盘总容量为:” &Format$(AllDiskTot al,“###,###") &个字节,即:” &Left(AllDiskTotal, 1) &. &Mid(AllDiskTotal, 2, 1) &“G,一共分了”&NUM &“个区,其中:"Label2.Caption = Label2.Caption &UCase(DrivePath) &“盘的整个容量为:" &diskTotal &“个字节" &",其剩余磁盘空间为:“&DiskSpace &" 个字节,磁盘已FAT“&SectorsPerCluster &",每个分区为:“&BytesPerSector &"个字节。
如何通过LABVIEW获取硬盘ID
通过LabVIEW获取硬盘序列号网上这类的帖子很多,不过差不多都是通过调用动态链接库实现的。
准确的说实现获取硬盘序列号的工作是由其他语言编写的DLL来实现的。
今天我的这例子不用调用动态链接库,直接由LabVIEW来获取硬盘的序列号。
这种方式在一个论坛上看见过,本想参考参考,不过楼主把VI加密了,索性自己做一个和大家分享,讨论讨论。
本程序读取的是硬盘的物理序列号,不同于DLL调用的方法,本方法获取的是硬盘唯一真正物理ID(是固化在硬盘BISO里的SN不是分区的SN),不会出现重复,也不可能被修改(或者说难度很大,而且还有危险,网上看到过说一个叫PC-3000的可以修改,没有尝试过,有哪位胆大拿自己硬盘试验一下,把结果共享一下吧)。
可用在软件加密中。
1、原理大家知道,硬盘相对于CPU来说属于外部设备,而CPU访问外部设备其实就是对外部IO的端口操作,这是硬盘的底层操作,对硬盘的任何操作都可以的,这样只要我们搞清楚如何通过IO指令对硬盘操作和硬盘物理序列号存放的寄存器就可以轻松读取我们所要的硬盘物理序列号了。
下面是从网络上搜集的一些资料。
硬盘读写端口的具体含义对硬盘进行操作的常用端口是1f0h~1f7h号端口,各端口含义如下:端口号读还是写具体含义1F0H 读/写用来传送读/写的数据(其内容是正在传输的一个字节的数据)1F1H 读用来读取错误码1F2H 读/写用来放入要读写的扇区数量1F3H 读/写用来放入要读写的扇区号码1F4H 读/写用来存放读写柱面的低8位字节1F5H 读/写用来存放读写柱面的高2位字节(其高6位恒为0)1F6H 读/写用来存放要读/写的磁盘号及磁头号第7位恒为 1第6位恒为0第5位恒为 1第4位为0代表第一块硬盘、为1代表第二块硬盘第3~0位用来存放要读/写的磁头号1f7H 读用来存放读操作后的状态第7位控制器忙碌第6位磁盘驱动器准备好了第5位写入错误第4位搜索完成第3位为1时扇区缓冲区没有准备好第2位是否正确读取磁盘数据第1位磁盘每转一周将此位设为1,第0位之前的命令因发生错误而结束写该位端口为命令端口,用来发出指定命令为50h 格式化磁道为20h 尝试读取扇区为21h 无须验证扇区是否准备好而直接读扇区为22h 尝试读取长扇区(用于早期的硬盘,每扇可能不是512字节,而是128字节到1024之间的值)为23h 无须验证扇区是否准备好而直接读长扇区为30h 尝试写扇区为31h 无须验证扇区是否准备好而直接写扇区为32h 尝试写长扇区为33h 无须验证扇区是否准备好而直接写长扇区上面是磁盘0的指令,下面是磁盘1的171H 1号硬盘错误寄存器172H 1号硬盘数据扇区计数173H 1号硬盘扇区数174H 1号硬盘柱面(低字节)175H 1号硬盘柱面(高字节)176H 1号硬盘驱动器/磁头寄存器177H 1号硬盘状态寄存器2、操作知道硬盘的IO操作指令了,下面就是如何在LabVIEW里去实现这些指令了。
基于Visual FoxPro的U盘物理序列号与盘符的获取方法
基于Visual FoxPro的U盘物理序列号与盘符的获取方法王永国
【期刊名称】《计算机时代》
【年(卷),期】2010(000)007
【摘要】基于Visal FoxPro环境,针对目前性价比高、可移性强的U盘,给出了其物理序列号与对应盘符的析出算法.该方法在软件保护和共享软件注册等方面具有一定的应用价值.
【总页数】4页(P44-47)
【作者】王永国
【作者单位】安徽大学数学科学学院,安徽,合肥,230039
【正文语种】中文
【相关文献】
1.基于Visual FoxPro的程序比较方法 [J], 熊发涯
2.基于VFP的U盘物理序列号与盘符的获取 [J], 王永国
3.基于U盘物理序列号的软件保护与注册方法研究 [J], 王永国
4.基于Visual FoxPro6.0开发小型应用系统的方法 [J], 索兴梅
5.基于Visual BASIC的U盘物理信息获取方法 [J], 王永国;王小云
因版权原因,仅展示原文概要,查看原文内容请购买。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
bIDEDeviceMap As Byte ' Bit map of IDE devices.
fCapabilities As Long ' Bit mask of driver capabilities.
Private Const CAP_IDE_EXECUTE_SMART_FUNCTION As Long = 4 ' SMART commannds supported
Private Type IDEREGS
bFeaturesReg As Byte ' Used for specifying SMART "commands".
Form中添加的程序:
Option Explicit
Private Sub Command1_Click()
'使用下面代码获取
Dim sn As String
sn = GetHardDiskInfo(hdPrimaryMaster, hdOnlySN)
Text1.Text = sn
dwReserved(3) As Long ' For future use.
End Type
Private Const CAP_IDE_ID_FUNCTION As Long = 1 ' ATA ID command supported
Private Const CAP_IDE_ATAPI_ID As Long = 2 ' ATAPI ID command supported
Public ay(16) As Integer
Private Type GETVERSIONOUTPARAMS
bVersion As Byte ' Binary driver version.
bRevision As Byte ' Binary driver revision.
Private Const IDE_EXECUTE_SMART_FUNCTION As Long = &HB0 ' Performs SMART cmd.
Private Const SMART_CYL_LOW As Long = &H4F
bCylHighReg As Byte ' IDE high order cylinder value
bDriveHeadReg As Byte ' IDE drive/head register
bCommandReg As Byte ' Actual IDE command.
Private Const READ_ATTRIBUTE_BUFFER_SIZE As Long = 512
Private Const IDENTIFY_BUFFER_SIZE As Long = 512
Private Const READ_THRESHOLD_BUFFER_SIZE As Long = 512
End Type
Private Const IDE_ATAPI_ID As Long = &HA1 ' Returns ID sector for ATAPI.
Private Const IDE_ID_FUNCTION As Long = &HEC ' Returns ID sector for ATA.
bReserved(2) As Byte ' Reserved for future expansion.
dwReserved(3) As Long ' For future use.
bBuffer(0) As Byte ' Input buffer.
End Sub
Private Sub Command2_Click()
End
End Sub
模块中的程序
Option Explicit
Private Const MAX_IDE_DRIVES As Long = 4 ' Max number of drives assuming primary/secondary, master/slave topology
irDriveRegs As IDEREGS ' Structure with drive register values.
bDriveNumber As Byte ' Physical drive number to send
' command to (0,1,2,3).
Private Const DFP_GET_VERSION As Long = &H74Байду номын сангаас80
Private Const DFP_SEND_DRIVE_COMMAND As Long = &H7C084
Private Const DFP_RECEIVE_DRIVE_DATA As Long = &H7C088
bReserved As Byte ' reserved for future use. Must be zero.
End Type
Private Type SENDCMDINPARAMS
cBufferSize As Long ' Buffer size in bytes
bSectorCountReg As Byte ' IDE sector count register
bSectorNumberReg As Byte ' IDE sector number register
bCylLowReg As Byte ' IDE low order cylinder value