当前位置:首页 » 硬盘大全 » 硬盘序列号c语言
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

硬盘序列号c语言

发布时间: 2022-07-01 23:22:42

① 如何用C语言取得计算机的机器特征码

有的,我通过google的代码搜索,找到一些。
给你添加在这里,作为参考,具体你可以去哪里自己搜搜,应该会有你想要的。有不懂m我。

using System;
using System.Collections;
using System.Management;

namespace ProctInfo
{
public class SystemInfo
{
private static IList cpuId;
private static IList driveId;
private static IList networkAdapterId;
private static string operationSystemName;
private static string proctId;

public static string OperationSystemName
{
get
{
if (string.IsNullOrEmpty(operationSystemName))
{
operationSystemName = GetOperationSystemInName();
}
return operationSystemName;
}
}

public static string MachineName
{
get { return Environment.MachineName; }
}

/// <summary>
/// 获取系统名称
/// </summary>
/// <returns></returns>
private static string GetOperationSystemInName()
{
OperatingSystem os = Environment.OSVersion;
string osName = "UNKNOWN";
switch (os.Platform)
{
case PlatformID.Win32Windows:
switch (os.Version.Minor)
{
case 0:
osName = "Windows 95";
break;
case 10:
osName = "Windows 98";
break;
case 90:
osName = "Windows ME";
break;
}
break;
case PlatformID.Win32NT:
switch (os.Version.Major)
{
case 3:
osName = "Windws NT 3.51";
break;
case 4:
osName = "Windows NT 4";
break;
case 5:
if (os.Version.Minor == 0)
{
osName = "Windows 2000";
}
else if (os.Version.Minor == 1)
{
osName = "Windows XP";
}
else if (os.Version.Minor == 2)
{
osName = "Windows Server 2003";
}
break;
case 6:
osName = "Longhorn";
break;
}
break;
}
return String.Format("{0}-{1}", osName, os.Version.ToString());
}

/// <summary>
/// CPU序列号
/// </summary>
public static IList CpuId
{
get
{
if (cpuId == null)
{
try
{
string cpuInfo = "";
ManagementClass cimobject = new ManagementClass("Win32_Processor");
ManagementObjectCollection moc = cimobject.GetInstances();
IList result = new ArrayList();
foreach (ManagementObject mo in moc)
{
cpuInfo = mo.Properties["ProcessorId"].Value.ToString();
result.Add(cpuInfo);
}
cpuId = result;
}
catch (Exception ex)
{
IList result = new ArrayList();
result.Add("--");
cpuId = result;
}
}
return cpuId;
}
}

/// <summary>
/// 硬盘序列号
/// </summary>
public static IList DriveId
{
get
{
if (driveId == null)
{
try
{
//获取硬盘ID
String HDid;
ManagementClass cimobject1 = new ManagementClass("Win32_DiskDrive");
ManagementObjectCollection moc1 = cimobject1.GetInstances();
IList result = new ArrayList();
foreach (ManagementObject mo in moc1)
{
HDid = (string) mo.Properties["Model"].Value;
result.Add(HDid);
}
driveId = result;
}
catch (Exception ex)
{
IList result = new ArrayList();
result.Add("--");
driveId = result;
}
}
return driveId;
}
}

/// <summary>
/// 获取网卡硬件地址
/// </summary>
public static IList NetworkAdapterId
{
get
{
if (networkAdapterId == null)
{
try
{
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc2 = mc.GetInstances();
IList result = new ArrayList();
foreach (ManagementObject mo in moc2)
{
if ((bool) mo["IPEnabled"] == true)
result.Add(mo["MacAddress"].ToString().Replace(":", "-"));
mo.Dispose();
}
networkAdapterId = result;
}
catch (Exception ex)
{
IList result = new ArrayList();
result.Add("--");
networkAdapterId = result;
}
}
return networkAdapterId;
}
}
}
}

② C语言 获取硬盘物理号

获取的大多数是磁盘序列号而已
物理号不容易获取
可以参考下
http://hiker2008.blog.51cto.com/10867/77918
就于逻辑序列号而言
我把VB改写成C的,可以参考下:
#include
#include
main()
{
DWORD
VolumeSerialNumber;
char
VolumeName[256];
GetVolumeInformation(
"c:\\
",
VolumeName,12,
&VolumeSerialNumber,
NULL,NULL,NULL,10
);
printf("c盘的卷标:%s
\n",VolumeName);
printf("c盘的序列号:%ld
\n",VolumeSerialNumber);
}

③ 关于C语言程序在一个固定电脑中运行,读取硬盘序列号的问题

之前收集的获取硬盘信息的函数语言是C++,可以成功获得硬盘驱动器的信息,希望能帮到您
void
CGetdiskinfo(DWORD
*dwNum,char
chDriveInfo[][256])//获取硬盘信息
{
DWORD
DiskCount
=
0;
//利用GetLogicalDrives()函数可以获取系统中逻辑驱动器的数量,函数返回的是一个32位无符号整型数据。
DWORD
DiskInfo
=
GetLogicalDrives();
//通过循环操作查看每一位数据是否为1,如果为1则磁盘为真,如果为0则磁盘不存在。
while(DiskInfo)
{
//通过位运算的逻辑与操作,判断是否为1
//Sleep(10);
if(DiskInfo&1)
{
DiskCount++;
}
DiskInfo
=
DiskInfo
>>
1;//通过位运算的右移操作保证每循环一次所检查的位置向右移动一位。*/
}
//
if
(*dwNum
<
DiskCount)
//
{
//
return;//实际的磁盘数目大于dwNum
//
}
*dwNum
=
DiskCount;//将磁盘分区数量保存
//-------------------------------------------------------------------//
//通过GetLogicalDriveStrings()函数获取所有驱动器字符串信息长度
int
DSLength
=
GetLogicalDriveStrings(0,NULL);
//
WCHAR*
DStr
=
new
WCHAR[DSLength];
char
*DStr=new
char[DSLength];
memset(DStr,0,DSLength);
//通过GetLogicalDriveStrings将字符串信息复制到堆区数组中,其中保存了所有驱动器的信息

④ 我有两个问题: 1.linux,shell脚本可以调用c程序吗 2.通过网卡mac地址与硬盘序列号怎么确定一个唯一序列

1、Linux的shell调用C语言是一定的,就像你在脚本中使用 echo "helloworld" | passwd --stdin user001一样啊。echo本身就是一个C语言的可行的二进制的可执行文件。
2、通过mac地址和硬盘序列号确定一台机器是可行的,通过将二者组合(比如mac地址+硬盘序列号)后,通过散列算法是可以得到一个唯一的16位的序列,但是这种算法是存在风险的,比如我更换了硬盘,那么对已你的系统来说还是以前的机器呢?还有就是mac地址是唯一的,但是硬盘的序列号不一定唯一,貌似现在的硬盘没有一个统一的编号管理机构,都是硬盘厂商自己对硬盘编号。

⑤ 用C语言怎么得到电脑的CPU序列号,硬盘序列号等信息

获取CPU序列号要使用 汇编指令

比较麻烦

static DWORD g_eax; // 存储返回的eax
static DWORD g_ebx; // 存储返回的ebx
static DWORD g_ecx; // 存储返回的ecx
static DWORD g_edx; // 存储返回的edx

void Executecpuid(DWORD veax)
{
asm("cpuid"
:"=a"(g_eax),
"=b"(g_ebx),
"=c"(g_ecx),
"=d"(g_edx)
:"a"(g_eax));
}
int isSupport;
void GetSerialNumber(WORD nibble[6])
{
Executecpuid(1); // 执行cpuid,参数为 eax = 1
isSupport = g_edx & (1<<18); // edx是否为1代表CPU是否存在序列号
if (FALSE == isSupport) // 不支持,返回false
{
return ;
}
Executecpuid(3); // 执行cpuid,参数为 eax = 3
memcpy(&nibble[4], &g_eax, 4); // eax为最高位的两个WORD
memcpy(&nibble[0], &g_ecx, 8); // ecx 和 edx为低位的4个WORD

}

⑥ 如何用C语言获取硬盘或主板或CPU的序列号

获取CPU序列号要使用
汇编指令
比较麻烦
static
DWORD
g_eax;
//
存储返回的eax
static
DWORD
g_ebx;
//
存储返回的ebx
static
DWORD
g_ecx;
//
存储返回的ecx
static
DWORD
g_edx;
//
存储返回的edx
void
Executecpuid(DWORD
veax)
{
asm("cpuid"
:"=a"(g_eax),
"=b"(g_ebx),
"=c"(g_ecx),
"=d"(g_edx)
:"a"(g_eax));
}
int
isSupport;
void
GetSerialNumber(WORD
nibble[6])
{
Executecpuid(1);
//
执行cpuid,参数为
eax
=
1
isSupport
=
g_edx
&
(1<<18);
//
edx是否为1代表CPU是否存在序列号
if
(FALSE
==
isSupport)
//
不支持,返回false
{
return
;
}
Executecpuid(3);
//
执行cpuid,参数为
eax
=
3
memcpy(&nibble[4],
&g_eax,
4);
//
eax为最高位的两个WORD
memcpy(&nibble[0],
&g_ecx,
8);
//
ecx

edx为低位的4个WORD
}

⑦ 如何用标准的C语言读取硬盘的序列号

标准C语言里面应该没有这个功能,磁盘物理或者逻辑山区的读取不算是C语言里面核心的部分,只是各种C的具体实现一般都包含了硬盘的读写功能。

⑧ linux下怎么用c获取硬盘物理序列号

1、在Linux系统中通过C语言获取硬盘序列号,可以借助于ioctl()函数,该函数原型如下:

intioctl(intfd,unsignedlongrequest,...);
ioctl的第一个参数是文件标识符,用open()函数打开设备时获取。
ioctl第二个参数为用于获得指定文件描述符的标志号,获取硬盘序列号,一般指明为HDIO_GET_IDENTITY。
ioctl的第三个参数为一些辅助参数,要获取硬盘序列号,需要借助于structhd_driveid结构体来保存硬盘信息,该结构体在Linux/hdreg.h中,structhd_driveid的声明如下
structhd_driveid{
unsignedshortconfig;/lotsofobsoletebitflags*/
unsignedshortcyls;/*Obsolete,"physical"cyls*/
unsignedshortreserved2;/*reserved(word2)*/
unsignedshortheads;/*Obsolete,"physical"heads*/
unsignedshorttrack_bytes;/*unformattedbytespertrack*/
unsignedshortsector_bytes;/*unformattedbytespersector*/
unsignedshortsectors;/*Obsolete,"physical"sectorspertrack*/
unsignedshortvendor0;/*vendorunique*/
unsignedshortvendor1;/*vendorunique*/
unsignedshortvendor2;/*Retiredvendorunique*/
unsignedcharserial_no[20];/*0=not_specified*/
unsignedshortbuf_type;/*Retired*/
unsignedshortbuf_size;/*Retired,512byteincrements
*0=not_specified
*/
……
};


2、源代码如下

#include<stdio.h>
//ioctl()的声明头文件
#include<sys/ioctl.h>
//硬盘参数头文件,hd_driveid结构声明头文件
#include<linux/hdreg.h>
//文件控制头文件
#include<sys/fcntl.h>
intmain()
{
//用于保存系统返回的硬盘数据信息
structhd_driveidid;
//这里以第一块硬盘为例,用户可自行修改
//用open函数打开获取文件标识符,类似于windows下的句柄
intfd=open("/dev/sda",O_RDONLY|O_NONBLOCK);
//失败返回
if(fd<0){
perror("/dev/sda");
return1;}
//调用ioctl()
if(!ioctl(fd,HDIO_GET_IDENTITY,&id))
{
printf("SerialNumber=%s ",id.serial_no);
}
return0;
}

编译完成后,执行效果如下: