磁盘序列号在每次软盘或硬盘格式化后都重新生成,并且不回重复。许多程序员用此加密。其实也可以修改该函数,可以得到磁盘卷标和文件系统类型信息。声明: Private Declare Function GetVolumeInformation Lib "kernel32.dll" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Integer, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long代码:Function GetSerialNumber(sRoot As String) As Long Dim lSerialNum As Long Dim R As Long Dim sTemp1 As String, sTemp2 As String strLabel = String$(255, Chr$(0)) ' 磁盘卷标 strType = String$(255, Chr$(0)) ' 文件系统类型 一般为 FAT R = GetVolumeInformation(sRoot, strLabel, Len(strLabel), lSerialNum, 0, 0, strType, Len(strType)) GetSerialNumber = lSerialNum '在 strLabel 中为 磁盘卷标 '在 strType 中为 文件系统类型 End Function用法:当驱动器不存在时,函数返回 0。如果是个非根目录,也将返回 0:lSerial = GetSerialNumber("c:\")
http://ygyuan.go.163.com/ http://ygyuan.3322.net/ 下载并安装"雁留声名录系统",然后你就可以得到第一个硬盘的序列号了!Private Declare Function GetDiskSN Lib "GetDiskSN.dll" (ByVal lpszSN As String) As DoubleDim s As String s = String(1024, Chr(0)) GetDiskSN (s) s = Trim(Replace(s, Chr(0), "")) msgbox s
轉自http://www.csdn.net/expert/topic/489/489705.shtm #include <windows.h> #include <stdio.h>WORD pw[256];static DWORD idt, int_idt; static DWORD Base; static WORD Entry;#pragma warning (disable:4035) static int inp(WORD rdx) { _asm xor eax, eax _asm mov dx, rdx _asm in al, dx }static WORD inpw(WORD rdx) { _asm xor eax, eax _asm mov dx, rdx _asm in ax, dx }static void outp(WORD rdx, int ral) { _asm mov dx, rdx _asm mov eax, ral _asm out dx, al }static int WaitIde() { int al; while ((al=inp(0x1F7))>=0x80) ; return al; }static void ReadIDE() { int al; int i; WaitIde(); outp(0x1F6,0xA0); al = WaitIde(); if ((al&0x50)!=0x50) return; outp(0x1F6,0xA0); outp(0x1F7,0xEC); al = WaitIde(); if ((al&0x58)!=0x58) return; for (i=0;i<256;i++) { pw[i] = inpw(0x1F0); } }static void __declspec( naked ) NowInRing0() { _asm { push ebp mov ebp,esp call ReadIDE cli mov ebx, int_idt mov ax, Entry mov word ptr [ebx-4], ax mov eax, Base shr eax, 16 mov [ebx+2], ax sti leave iretd } }void GetIDEInfo() { DWORD dwExcept; dwExcept = (DWORD)NowInRing0; _asm { mov eax, fs:[0] push eax sidt [esp-02h] pop ebx mov idt, ebx add ebx, 0x1C mov int_idt, ebx mov eax, [ebx] mov [Base], eax mov ax, [ebx-4] mov [Entry], ax cli mov esi, dwExcept push esi mov [ebx-4], si shr esi, 16 mov [ebx+2], si pop esi sti int 3 } }main() { char s[80]; register i,j; GetIDEInfo(); for (i=0,j=0;i<10;i++) { s[j++]=pw[10+i]>>8; s[j++]=pw[10+i]&0xFF; } s[j] = 0; printf("Serial=%s\n", s); return 0; }
这个程序一定是对的;须注意的是如果返回的是逻辑驱动器则是Volume 'even this will bring up same result: 'you will get two different serail number for the two drives. 'It seems as if logical drives get their own serial number... Private 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 Private Sub Form_Load() 'KPD-Team 1998 'URL: http://www.allapi.net/ 'E-Mail: [email protected] Dim Serial As Long, VName As String, FSName As String 'Create buffers VName = String$(255, Chr$(0)) FSName = String$(255, Chr$(0)) 'get the volume information GetVolumeInformation "C:\", VName, 255, Serial, 0, 0, FSName, 255 'Strip the extra chr$(0)'s VName = Left$(VName, InStr(1, VName, Chr$(0)) - 1) FSName = Left$(FSName, InStr(1, FSName, Chr$(0)) - 1) MsgBox "The Volume name of C:\ is '" + VName + "', the File system name of C:\ is '" + FSName + "' and the serial number of C:\ is '" + Trim(Str$(Serial)) + "'", vbInformation + vbOKOnly, App.Title End Sub
Win2K好象可以用CreateFile("......")打开物理驱动器,具体不清楚。(不确定,可能是错的)
可以到C区试试。不过有些硬盘是没有序列号的。
白痴的回答!
Private Declare Function GetVolumeInformation Lib "kernel32.dll" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Integer, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long代码:Function GetSerialNumber(sRoot As String) As Long
Dim lSerialNum As Long
Dim R As Long
Dim sTemp1 As String, sTemp2 As String
strLabel = String$(255, Chr$(0))
' 磁盘卷标
strType = String$(255, Chr$(0))
' 文件系统类型 一般为 FAT
R = GetVolumeInformation(sRoot, strLabel, Len(strLabel), lSerialNum, 0, 0, strType, Len(strType))
GetSerialNumber = lSerialNum
'在 strLabel 中为 磁盘卷标
'在 strType 中为 文件系统类型
End Function用法:当驱动器不存在时,函数返回 0。如果是个非根目录,也将返回 0:lSerial = GetSerialNumber("c:\")
你说的还是磁盘的卷标,我是想要硬盘的序列号,是生产厂家写入硬盘控制芯片的那个序列号,每个硬盘的序列号都不重复,也不会随磁盘的格式化而改变。
不知道有没有办法能取到。
我下载过一个小软件能取出硬盘的序列号,但不知道他是怎么做的。
http://ygyuan.3322.net/
下载并安装"雁留声名录系统",然后你就可以得到第一个硬盘的序列号了!Private Declare Function GetDiskSN Lib "GetDiskSN.dll" (ByVal lpszSN As String) As DoubleDim s As String
s = String(1024, Chr(0))
GetDiskSN (s)
s = Trim(Replace(s, Chr(0), ""))
msgbox s
#include <windows.h>
#include <stdio.h>WORD pw[256];static DWORD idt, int_idt;
static DWORD Base;
static WORD Entry;#pragma warning (disable:4035)
static int inp(WORD rdx)
{
_asm xor eax, eax
_asm mov dx, rdx
_asm in al, dx
}static WORD inpw(WORD rdx)
{
_asm xor eax, eax
_asm mov dx, rdx
_asm in ax, dx
}static void outp(WORD rdx, int ral)
{
_asm mov dx, rdx
_asm mov eax, ral
_asm out dx, al
}static int WaitIde()
{
int al; while ((al=inp(0x1F7))>=0x80) ;
return al;
}static void ReadIDE()
{
int al;
int i; WaitIde();
outp(0x1F6,0xA0);
al = WaitIde();
if ((al&0x50)!=0x50) return; outp(0x1F6,0xA0);
outp(0x1F7,0xEC);
al = WaitIde();
if ((al&0x58)!=0x58) return; for (i=0;i<256;i++) {
pw[i] = inpw(0x1F0);
}
}static void __declspec( naked ) NowInRing0()
{
_asm {
push ebp
mov ebp,esp call ReadIDE cli
mov ebx, int_idt
mov ax, Entry
mov word ptr [ebx-4], ax
mov eax, Base
shr eax, 16
mov [ebx+2], ax
sti
leave
iretd
}
}void GetIDEInfo()
{
DWORD dwExcept; dwExcept = (DWORD)NowInRing0; _asm {
mov eax, fs:[0]
push eax
sidt [esp-02h]
pop ebx
mov idt, ebx
add ebx, 0x1C
mov int_idt, ebx mov eax, [ebx]
mov [Base], eax
mov ax, [ebx-4]
mov [Entry], ax cli
mov esi, dwExcept
push esi
mov [ebx-4], si
shr esi, 16
mov [ebx+2], si
pop esi
sti int 3
}
}main()
{
char s[80];
register i,j; GetIDEInfo(); for (i=0,j=0;i<10;i++) {
s[j++]=pw[10+i]>>8;
s[j++]=pw[10+i]&0xFF;
}
s[j] = 0; printf("Serial=%s\n", s); return 0;
}
'you will get two different serail number for the two drives.
'It seems as if logical drives get their own serial number...
Private 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
Private Sub Form_Load()
'KPD-Team 1998
'URL: http://www.allapi.net/
'E-Mail: [email protected]
Dim Serial As Long, VName As String, FSName As String
'Create buffers
VName = String$(255, Chr$(0))
FSName = String$(255, Chr$(0))
'get the volume information
GetVolumeInformation "C:\", VName, 255, Serial, 0, 0, FSName, 255
'Strip the extra chr$(0)'s
VName = Left$(VName, InStr(1, VName, Chr$(0)) - 1)
FSName = Left$(FSName, InStr(1, FSName, Chr$(0)) - 1)
MsgBox "The Volume name of C:\ is '" + VName + "', the File system name of C:\ is '" + FSName + "' and the serial number of C:\ is '" + Trim(Str$(Serial)) + "'", vbInformation + vbOKOnly, App.Title
End Sub
http://www.csdn.net/expert/topic/629/629600.xml?temp=.8035089
Copyright (c) 2002 Lonsoft Studio.
All Rights Reserved作者: [email protected]
注册: [email protected] (注册时使用)
Web:http://www.dapha.net/lonsoft/index.htm
Oicq: 8892098(请留言)
--控件介绍 -----------------------LonSoft Hard-Disk Serial ActiveX是一个32位ActiveX控件,
用于获取你的计算机硬盘的相关信息,包括序列号、型号、修订号、
磁盘缓存大小、磁头数、柱面数、每磁道的扇区数等。
如果你是共享软件的作者,你可以利用这些信息做什么呢?---控件使用-----------------
属性:1.Controller:取得硬盘控制器
返回值: 0=Primary Controller 1=Secondary Controller
2=Tertiary Controller 3=Quaternary Controller 2.ControllerType:取得硬盘控制器是在主盘还是在副盘
返回值: 0=主盘 1=副盘3.DriveType:驱动器类型
返回值:"Removable"; "Fixed"; "Unknow";4.SerialNumber:硬盘序列号
返回值:返回硬盘序列号的字符串。5.ModelNumber:硬盘型号
返回值:返回硬盘型号的字符串。如"QUANTUM FIREBALLP LM10.2"6.RevisionNumber:硬盘修订号
返回值:返回硬盘修订号,字符串。7.RevisionNumber:硬盘缓存的大小
返回值:返回硬盘缓存的大小,字符串。8.Heads:硬盘的磁头数
返回值:返回硬盘的磁头数,字符串。9.Cylinders:硬盘的柱面数
返回值:返回硬盘的柱面数,字符串。10.Sectors:硬盘的每磁道的扇区数
返回值:返回硬盘每磁道的扇区数,字符串。11.ComputerID:与用户计算机相关的序列号
返回值:返回与用户计算机相关的序列号,字符串。如196727438等...方法:语法: ReadDiskSerial (<RegName>,<RegCode>)
功能:读取硬盘的资料。
参数:regName为注册名,regCode为注册序列号
返回值:Ture 注册名及注册序号有效;否则弹出一对话框。 这个控件就是用VB编的!