當前位置:首頁 » 硬碟大全 » 硬碟序列號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;
}

編譯完成後,執行效果如下: