wmi硬盘序列号
我很荣幸能够为大家解答关于wmi硬盘序列号的问题。这个问题集合囊括了wmi硬盘序列号的各个方面,我将从多个角度给出答案,以期能够满足您的需求。
1.下面是DELPHI中获取电脑硬盘物理序列号的代码(网友写给)
2.请教,VBS脚本怎么获取电脑硬件序列号?
3.用VB做了个程序,怎么给它加注册码阿?
4.C# 如何获取所有硬盘(包含移动硬盘组/盒里的硬盘)的厂家序列号 和 硬盘对应的所有盘符
下面是DELPHI中获取电脑硬盘物理序列号的代码(网友写给)
1、网上的半瓶子醋很多(包括我),当然,百度更多。GetVolumeInformation是获取分区序列号,不是物理序列号,重装系统、格式化硬盘就会变,甚至用软件都能修改。还有一种WMI方法,不过不保险(有的硬盘ID前面有空字符)。比较保险的是DeviceIoControl函数,代码较长。
2、如果楼主喜欢那个GetVolumeInformation,那可以继续用下去,当我没回帖。如果想获取真正的物理序列号,可以试试下面代码。
uses Windows, SysUtils;
type
TIDERegs = packed record
bFeaturesReg: Byte;
bSectorCountReg: Byte;
bSectorNumberReg: Byte;
bCylLowReg: Byte;
bCylHighReg: Byte;
bDriveHeadReg: Byte;
bCommandReg: Byte;
bReserved: Byte;
end;
TSendCmdInParams = packed record
cBufferSize: DWORD;
irDriveRegs: TIDERegs;
bDriveNumber: Byte;
bReserved: array[0..2] of Byte;
dwReserved: array[0..3] of DWORD;
bBuffer: array[0..0] of Byte;
end;
PIdSector = ^TIdSector;
TIdSector = packed record
wGenConfig: Word;
wNumCyls: Word;
wReserved: Word;
wNumHeads: Word;
wBytesPerTrack: Word;
wBytesPerSector: Word;
wSectorsPerTrack: Word;
wVendorUnique: array[0..2] of Word;
sSerialNumber: array[0..19] of Char;
wBufferType: Word;
wBufferSize: Word;
wECCSize: Word;
sFirmwareRev: array[0..7] of Char;
sModelNumber: array[0..39] of Char;
wMoreVendorUnique: Word;
wDoubleWordIO: Word;
wCapabilities: Word;
wReserved1: Word;
wPIOTiming: Word;
wDMATiming: Word;
wBS: Word;
wNumCurrentCyls: Word;
wNumCurrentHeads: Word;
wNumCurrentSectorsPerTrack: Word;
ulCurrentSectorCapacity: DWORD;
wMultSectorStuff: Word;
ulTotalAddressableSectors: DWORD;
wSingleWordDMA: Word;
wMultiWordDMA: Word;
bReserved: array[0..127] of Byte;
end;
TDriverStatus = packed record
bDriverError: Byte;
bIDEStatus: Byte;
bReserved: array[0..1] of Byte;
dwReserved: array[0..1] of DWORD;
end;
TSendCmdOutParams = packed record
cBufferSize: DWORD;
DriverStatus: TDriverStatus;
bBuffer: array[0..0] of Byte;
end;
procedure ChangeByteOrder(var Data; Size: Integer);
var
p: PChar;
i: Integer;
c: Char;
begin
p := @Data;
for i := 0 to (Size shr 1) - 1 do
begin
c := p^;
p^ := (p + 1)^;
(p + 1)^ := c;
Inc(p, 2);
end;
end;
function DiskSerialNo: string;
const
IDENTIFY_BUFFER_SIZE = 512;
var
hDevice: THandle;
cbBytesReturned: DWORD;
SCIP: TSendCmdInParams;
aIdOutCmd: array[0..(SizeOf(TSendCmdOutParams) + IDENTIFY_BUFFER_SIZE - 1) - 1] of Byte;
IdOutCmd: TSendCmdOutParams absolute aIdOutCmd;
begin
if Win32Platform = VER_PLATFORM_WIN32_NT then
hDevice := CreateFile('\\.\PhysicalDrive0', GENERIC_READ or GENERIC_WRITE,
FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0)
else hDevice := CreateFile('\\.\SMARTVSD', 0, 0, nil, CREATE_NEW, 0, 0);
if hDevice = INVALID_HANDLE_VALUE then Exit;
FillChar(SCIP, SizeOf(TSendCmdInParams) - 1, #0);
FillChar(aIdOutCmd, SizeOf(aIdOutCmd), #0);
cbBytesReturned := 0;
SCIP.cBufferSize := IDENTIFY_BUFFER_SIZE;
SCIP.irDriveRegs.bSectorCountReg := 1;
SCIP.irDriveRegs.bSectorNumberReg := 1;
SCIP.irDriveRegs.bDriveHeadReg := $A0;
SCIP.irDriveRegs.bCommandReg := $EC;
if DeviceIoControl(hDevice, $0007C088, @SCIP, SizeOf(TSendCmdInParams) - 1,
@aIdOutCmd, SizeOf(aIdOutCmd), cbBytesReturned, nil) then
begin
with PIdSector(@IdOutCmd.bBuffer)^ do
begin
ChangeByteOrder(sSerialNumber, SizeOf(sSerialNumber));
(Pchar(@sSerialNumber) + SizeOf(sSerialNumber))^ := #0;
Result := Pchar(@sSerialNumber);
end;
end;
CloseHandle(hDevice);
end;
请教,VBS脚本怎么获取电脑硬件序列号?
很难达到你的要求的,VB好像是获取不到硬盘的物理序列号的,只能获取到某一个分区的序列号.不过可以调用其它的程序写的获取硬盘物理序列号的dll来获取,CPU的序列号我用的是wmi.VB本来对底层方面就不是很好
引用api获得硬盘序列号
Private Declare Function MymachineC 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()
Dim AA, 硬盘序列号, Maxlen, Sysflag As Long: Dim VolName, FsysName As String
AA = MymachineC("c:\", VolName, 256, 硬盘序列号, Maxlen, Sysflag, FsysName, 256)
msgbox "C硬盘序列号-机器码啦-(16制): " & Hex(硬盘序列号)
End Sub
用VB做了个程序,怎么给它加注册码阿?
dim bsb,cpu,disk
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_BaseBoard",,48)
For Each objItem in colItems
bsb = "BaseBoard SerialNumber: " & objItem.SerialNumber & vbCrlf & bsb
Next
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_Processor",,48)
For Each objItem in colItems
cpu = "CPU ProcessorId: " & objItem.ProcessorId & vbCrlf & cpu
Next
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_DiskDrive",,48)
For Each objItem in colItems
disk = "DiskDrive SerialNumber: " & objItem.SerialNumber & vbCrlf & disk
Next
dim fso, f
set fso = CreateObject("Scripting.FileSystemObject")
set f = fso.CreateTextFile("D:\test.txt", true) '第二个参数表示目标文件存在时是否覆盖
f.Write(bsb)
f.Write(cpu)
f.Write(disk)
f.Close()
set f = nothing
set fso = nothing
MsgBox "已完成!"
复制到文本,另存为,右下角编码选择ANSI,类型选择所有,文件名:HWinfo.vbs
C# 如何获取所有硬盘(包含移动硬盘组/盒里的硬盘)的厂家序列号 和 硬盘对应的所有盘符
一般是这样操作的!读取硬盘序列号及CPU序列号进行右逆运算进行加密产生注册码,将加密串进行解密后再进行不可逆加密算法产生激活码传回进行激活!具体算法网上可找到,改些参数就可以了读取硬盘序列号 api 函数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可读取硬盘序列号以下是读取CPU序列号的代码Public Function GetwmiProcessorID() As String
Dim cpuSet As SWbemObjectSet
Dim cpu As SWbemObjectSet cpuSet = GetObject("winmgmts:{impersonationLevel=impersonate}"). InstancesOf("Win32_Processor")
For Each cpu In cpuSet
GetwmiProcessorID = cpu.processorid
NextEnd Function
#include #include #include #define BUFSIZE 1024BOOL GetDirverInfo(LPSTR szDrive);void main(void){CHAR szLogicalDriveStrings[BUFSIZE];PCHAR szDrive;ZeroMemory(szLogicalDriveStrings,BUFSIZE);GetLogicalDriveStrings(BUFSIZE - 1,szLogicalDriveStrings); szDrive = (PCHAR)szLogicalDriveStrings;do{if(!GetDirverInfo(szDrive)){printf("\nGet Volume Information Error: %d", GetLastError());}szDrive += (lstrlen(szDrive)+1);}while(*szDrive!='\x00');getchar();}BOOL GetDirverInfo(LPSTR szDrive){UINT uDriveType;DWORD dwVolumeSerialNumber;DWORD dwMaximumComponentLength;DWORD dwFileSystemFlags;TCHAR szFileSystemNameBuffer[BUFSIZE];printf("\n%s\n",szDrive);uDriveType = GetDriveType(szDrive);printf("------%d %d\n",uDriveType,szDrive);switch(uDriveType){case DRIVE_UNKNOWN:printf("未知的磁盘类型");break;case DRIVE_NO_ROOT_DIR:printf("说明lpRootPathName是无效的");break;case DRIVE_REMOVABLE:printf("可移动磁盘");break;case DRIVE_FIXED:printf("固定磁盘");break;case DRIVE_REMOTE:printf("网络磁盘");break;case DRIVE_CDROM:printf("光驱");break;case DRIVE_RAMDISK:printf("为RAM");break;default:break;}if (!GetVolumeInformation(szDrive, NULL, 0,&dwVolumeSerialNumber,&dwMaximumComponentLength,&dwFileSystemFlags,szFileSystemNameBuffer,BUFSIZE)){return FALSE;}printf ("\nVolume Serial Number is %u",dwVolumeSerialNumber);printf ("\nMaximum Component Length is %u",dwMaximumComponentLength);printf ("\nSystem Type is %s\n",szFileSystemNameBuffer);if(dwFileSystemFlags & FILE_SUPPORTS_REPARSE_POINTS){printf ("The file system does not support volume mount points.\n");}if(dwFileSystemFlags & FILE_VOLUME_QUOTAS){printf ("The file system supports disk quotas.\n");}if(dwFileSystemFlags & FILE_CASE_SENSITIVE_SEARCH){printf ("The file system supports case-sensitive file names.\n");}//you can use these value to get more informaion////FILE_CASE_PRESERVED_NAMES//FILE_CASE_SENSITIVE_SEARCH//FILE_FILE_COMPRESSION//FILE_NAMED_STREAMS//FILE_PERSISTENT_ACLS//FILE_READ_ONLY_VOLUME//FILE_SUPPORTS_ENCRYPTION//FILE_SUPPORTS_OBJECT_IDS//FILE_SUPPORTS_REPARSE_POINTS//FILE_SUPPORTS_SPARSE_FILES//FILE_UNICODE_ON_DISK//FILE_VOLUME_IS_COMPRESSED//FILE_VOLUME_QUOTASprintf("...\n");return TRUE;}
好了,今天关于“wmi硬盘序列号”的探讨就到这里了。希望大家能够对“wmi硬盘序列号”有更深入的认识,并且从我的回答中得到一些帮助。
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。