windows x下的c编程,获取电脑硬件序列号(cpu 硬盘 bios 主版)!很着急!邮箱wangyu850722@163.com
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了windows x下的c编程,获取电脑硬件序列号(cpu 硬盘 bios 主版)!很着急!邮箱wangyu850722@163.com相关的知识,希望对你有一定的参考价值。
参考技术A 1、取得磁盘序列号、卷标和文件系统类型磁盘序列号在每次软盘或硬盘格式化后都重新生成,并且不回重复。许多程序员用此加密。其实也可以修改该函数,可以得到磁盘卷标和文件系统类型信息。
声明:
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:\")
2、 大家只需将以下代码拈贴到VB的工程中,并以类的模式保存即可使用。所有的代码我都已经测试过,并曾在多次开发项目中使用过。
使用方法:
dim oHard as new CGetHardInfo '您可将CGetHardInfo 替换成您保存的类
读取硬盘的序列号:
HDDSR=CGetHardInfo.HardDiskID '读取C盘的串号 (默认值)
如果获取其他盘符的序列号则需要指明盘符如下:
CGetHardInfo.HardDrive="D"
HDDSR=CGetHardInfo.HardDiskID '读取D盘的串号
获得网卡的串号:
NICID=CGetHardInfo.NicID
获取本机的IP地址:
IPAddress=CGethardInfo.IPAddress
获取主机名称:
HostName=CGetHardInfo.HostName
如果产生错误(比如没有网卡等)可利用LASTERROR返回产生的最后一个错误 ERRORs为产生的错误集合
以下为获取硬件信息的完整代码
'=================================================================
'获取相关的硬件信息 (硬盘ID/网卡ID/主机名称/IP地址)
'文件名称: GetHardInfo.cls
'开发时间: 2001.10.30
'=================================================================
Option Explicit
Private Const NCBASTAT = &H33
Private Const NCBNAMSZ = 16
Private Const HEAP_ZERO_MEMORY = &H8
Private Const HEAP_GENERATE_EXCEPTIONS = &H4
Private Const NCBRESET = &H32
Private Type NCB
ncb_command As Byte
ncb_retcode As Byte
ncb_lsn As Byte
ncb_num As Byte
ncb_buffer As Long
ncb_length As Integer
ncb_callname As String * NCBNAMSZ
ncb_name As String * NCBNAMSZ
ncb_rto As Byte
ncb_sto As Byte
ncb_post As Long
ncb_lana_num As Byte
ncb_cmd_cplt As Byte
ncb_reserve(9) As Byte ' Reserved, must be 0
ncb_event As Long
End Type
Private Type ADAPTER_STATUS
adapter_address(5) As Byte 'As String * 6
rev_major As Byte
reserved0 As Byte
adapter_type As Byte
rev_minor As Byte
duration As Integer
frmr_recv As Integer
frmr_xmit As Integer
iframe_recv_err As Integer
xmit_aborts As Integer
xmit_success As Long
recv_success As Long
iframe_xmit_err As Integer
recv_buff_unavail As Integer
t1_timeouts As Integer
ti_timeouts As Integer
Reserved1 As Long
free_ncbs As Integer
max_cfg_ncbs As Integer
max_ncbs As Integer
xmit_buf_unavail As Integer
max_dgram_size As Integer
pending_sess As Integer
max_cfg_sess As Integer
max_sess As Integer
max_sess_pkt_size As Integer
name_count As Integer
End Type
Private Type NAME_BUFFER
Name As String * NCBNAMSZ
name_num As Integer
name_flags As Integer
End Type
Private Type ASTAT
adapt As ADAPTER_STATUS
NameBuff(30) As NAME_BUFFER
End Type
Private Declare Function Netbios Lib "netapi32.dll" (pncb As NCB) As Byte
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, ByVal hpvSource As Long, ByVal cbCopy As Long)
Private Declare Function GetProcessHeap Lib "kernel32" () As Long
Private Declare Function HeapAlloc Lib "kernel32" (ByVal hHeap As Long, ByVal dwFlags As Long, ByVal dwBytes As Long) As Long
Private Declare Function HeapFree Lib "kernel32" (ByVal hHeap As Long, ByVal dwFlags As Long, lpMem As Any) As Long
3、磁盘序列号在每次软盘或硬盘格式化后都重新生成,并且不回重复。许多程序员用此加密。其实也可以修改该函数,可以得到磁盘卷标和文件系统类型信息。
声明:
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 strLabel As String, strType 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:\")
Windows下的systeminfo命令获取系统信息
该命令是Windows中用于显示关于计算机及其操作系统的详细配置信息,包括操作系统配置、安全信息、产品 ID 和硬件属性,如 RAM、磁盘空间和网卡和补丁信息等。
简介
Systeminfo(命令行)显示关于计算机及其操作系统的详细配置信息,包括操作系统配置、安全信息、产品 ID 和硬件属性,如 RAM、磁盘空间和网卡。
语法
Systeminfo [/s Computer [/u Domain\\UserName[/p Password]]] [/fo TABLE | LIST | CSV] [/nh]
参数
/s Computer
指定远程计算机名称或IP地址(不能使用反斜杠)。默认值是本地计算机。
/u Domain\\UserName
使用UserName或 Domain\\UserName指定的用户帐户权限运行该命令。默认值是当前登录计算机并发出命令的用户具有的权限。
/p Password
指出 /u 参数中指定的用户帐户的密码。
/fo:TABLE|LIST|CSV
Table:以表格形式显示输出。
List:以列表形式显示输出。
Csv:以“逗号分隔值”格式显示输出。
/nh
取消输出结果中的列标题。只有在 /fo参数设置为 TABLE 或 CSV 时有效。
注释:使用 /s、/u 和 /p 命令行选项。只有在使用使用 /s 时才可使用 /u 和 /p 命令行选项。必须同时使用 /p 和 /u 才能提供用户密码。
实例:
以上是关于windows x下的c编程,获取电脑硬件序列号(cpu 硬盘 bios 主版)!很着急!邮箱wangyu850722@163.com的主要内容,如果未能解决你的问题,请参考以下文章
C语言获取硬件信息(CPU序列号,硬盘序列号,网卡IPMAC地址是否插入网线)
Windows 环境下的 Socket 编程 2 - 地址族与数据序列
Windows 环境下的 Socket 编程 2 - 地址族与数据序列