A. 怎样在vc++中获得硬盘的序列号
vc++中获得硬盘的序列号可以参考如下代码:圆键
//MyDiskInfo.h头文件
#pragma once
class MyDiskInfo
{
public:
MyDiskInfo(void);
public:
~MyDiskInfo(void);
public:
int GetDiskInfo(int driver=0);
char szModelNumber[64];
char szSerialNumber[64];
};
/橘凯巧/MyDiskInfo.cpp文件
// MyDiskInfo.cpp: implementation of the CMyDiskInfo class.
//
#include "stdafx.h"
#include "MyDiskInfo.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
const WORD IDE_ATAPI_IDENTIFY = 0xA1; // 读取ATAPI设备的命令
const WORD IDE_ATA_IDENTIFY = 0xEC; // 读取ATA设备的命令
#define _WIN32_WINNT 0x0400
#include "winioctl.h"
//孙雹#include "NTDDSCSI.h"
// Construction/Destruction
MyDiskInfo::MyDiskInfo(void)
{
}
MyDiskInfo::~MyDiskInfo(void)
{
}
BOOL __fastcall DoIdentify( HANDLE hPhysicalDriveIOCTL,
PSENDCMDINPARAMS pSCIP,
PSENDCMDOUTPARAMS pSCOP,
BYTE btIDCmd,
BYTE btDriveNum,
PDWORD pdwBytesReturned)
{
pSCIP->cBufferSize = IDENTIFY_BUFFER_SIZE;
pSCIP->irDriveRegs.bFeaturesReg = 0;
pSCIP->irDriveRegs.bSectorCountReg = 1;
pSCIP->irDriveRegs.bSectorNumberReg = 1;
pSCIP->irDriveRegs.bCylLowReg = 0;
pSCIP->irDriveRegs.bCylHighReg = 0;
pSCIP->irDriveRegs.bDriveHeadReg = (btDriveNum & 1) ? 0xB0 : 0xA0;
pSCIP->irDriveRegs.bCommandReg = btIDCmd;
pSCIP->bDriveNumber = btDriveNum;
pSCIP->cBufferSize = IDENTIFY_BUFFER_SIZE;
return DeviceIoControl( hPhysicalDriveIOCTL,
SMART_RCV_DRIVE_DATA,
(LPVOID)pSCIP,
sizeof(SENDCMDINPARAMS) - 1,
(LPVOID)pSCOP,
sizeof(SENDCMDOUTPARAMS) + IDENTIFY_BUFFER_SIZE - 1,
pdwBytesReturned, NULL);
}
char *__fastcall ConvertToString(DWORD dwDiskData[256], int nFirstIndex, int nLastIndex)
{
static char szResBuf[1024];
char ss[256];
int nIndex = 0;
int nPosition = 0;
for(nIndex = nFirstIndex; nIndex <= nLastIndex; nIndex++)
{
ss[nPosition] = (char)(dwDiskData[nIndex] / 256);
nPosition++;
// Get low BYTE for 2nd character
ss[nPosition] = (char)(dwDiskData[nIndex] % 256);
nPosition++;
}
// End the string
ss[nPosition] = '\0';
int i, index=0;
for(i=0; i <nPosition; i++)
{
if(ss[i]==0 || ss[i]==32) continue;
szResBuf[index]=ss[i];
index++;
}
szResBuf[index]=0;
return szResBuf;
}
int MyDiskInfo::GetDiskInfo(int driver)
{
char sFilePath[64]={0};
sprintf(sFilePath,"\\\\.\\PHYSICALDRIVE%d",driver);//modify by lonkil 2008-07-13
HANDLE hFile = INVALID_HANDLE_VALUE;
hFile = ::CreateFile(sFilePath,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING,
0, NULL);
if (hFile == INVALID_HANDLE_VALUE) return -1;
DWORD dwBytesReturned;
GETVERSIONINPARAMS gvopVersionParams;
DeviceIoControl(hFile,
SMART_GET_VERSION,
NULL,
0,
&gvopVersionParams,
sizeof(gvopVersionParams),
&dwBytesReturned, NULL);
if(gvopVersionParams.bIDEDeviceMap <= 0) return -2;
// IDE or ATAPI IDENTIFY cmd
int btIDCmd = 0;
SENDCMDINPARAMS InParams;
int nDrive =0;
btIDCmd = (gvopVersionParams.bIDEDeviceMap >> nDrive & 0x10) ? IDE_ATAPI_IDENTIFY : IDE_ATA_IDENTIFY;
// 输出参数
BYTE btIDOutCmd[sizeof(SENDCMDOUTPARAMS) + IDENTIFY_BUFFER_SIZE - 1];
if(DoIdentify(hFile,
&InParams,
(PSENDCMDOUTPARAMS)btIDOutCmd,
(BYTE)btIDCmd,
(BYTE)nDrive, &dwBytesReturned) == FALSE) return -3;
::CloseHandle(hFile);
DWORD dwDiskData[256];
USHORT *pIDSector; // 对应结构IDSECTOR,见头文件
pIDSector = (USHORT*)((SENDCMDOUTPARAMS*)btIDOutCmd)->bBuffer;
for(int i=0; i < 256; i++) dwDiskData[i] = pIDSector[i];
// 取系列号
ZeroMemory(szSerialNumber, sizeof(szSerialNumber));
strcpy(szSerialNumber, ConvertToString(dwDiskData, 10, 19));
// 取模型号
ZeroMemory(szModelNumber, sizeof(szModelNumber));
strcpy(szModelNumber, ConvertToString(dwDiskData, 27, 46));
return 0;
}
B. 硬盘怎么查看序列号
下面是查看硬盘序列号的步骤:
1.首先敲击键盘的“WIN+R”键,然后在打开的运行窗口里输入cmd,再点确定。
电脑硬盘序列号电脑图解5
C. WIN10 C++获取CPU和硬盘序列号
首先老袜打开运行窗口,在运行窗口中输侍嫌激入cmd进入命令提示符。 然后在命令提示符中执行命令diskpart来查看硬盘序列号。 接着执行list disk把硬盘列表显示出来,图中显示只有一个硬盘。 输入select disk 0回车选择硬盘。 最后输入命令detail disk即可把硬盘信息显示出来了,在者御硬盘信息中我们就能够看到硬盘序列号了。
D. 获取硬盘序列号
不拆机情况下获取计算机硬盘序列号的方法(Window 操返冲作系统下):
运行 cmd
输入命蔽世信令 >>wmic diskdrive get serialnumber
另外,工具宏轮推荐HardDisk Setinel
E. 如何查看电脑硬盘序列号
1、首先在开始菜单栏中输入cmd。
F. VC++如何获取机器码硬盘序列号、CPU编号、BIOS编号等~
可以试试使用WMI(在msdn上有详细的信息):
硬盘序列号:
用Win32_PhysicalMedia
class.
CPU编号:
用Win32_Processor
class.
BIOS编号:
用Win32_BIOS
class.
下面例子取得硬盘的序列号,其他的用法也类似(msdn上的例子,把Win32_OperatingSystem改成了Win32_PhysicalMedia):
#define
_WIN32_DCOM
#include
<iostream>
using
namespace
std;
#include
<comdef.h>
#include
<Wbemidl.h>
#
pragma
comment(lib,
"wbemuuid.lib")
int
main(int
argc,
char
**argv)
{
HRESULT
hres;
//
Step
1:
--------------------------------------------------
//
Initialize
COM.
------------------------------------------
hres
=
CoInitializeEx(0,
COINIT_MULTITHREADED);
if
(FAILED(hres))
{
cout
<<
"Failed
to
initialize
COM
library.
Error
code
=
0x"
<<
hex
<<
hres
<<
endl;
return
1;
//
Program
has
failed.
}
//
Step
2:
--------------------------------------------------
//
Set
general
COM
security
levels
--------------------------
//
Note:
If
you
are
using
Windows
2000,
you
need
to
specify
-
//
the
default
authentication
credentials
for
a
user
by
using
//
a
SOLE_AUTHENTICATION_LIST
structure
in
the
pAuthList
----
//
parameter
of
CoInitializeSecurity
------------------------
hres
=
CoInitializeSecurity(
NULL,
-1,
//
COM
authentication
NULL,
//
Authentication
services
NULL,
//
Reserved
RPC_C_AUTHN_LEVEL_DEFAULT,
//
Default
authentication
RPC_C_IMP_LEVEL_IMPERSONATE,
//
Default
Impersonation
NULL,
//
Authentication
info
EOAC_NONE,
//
Additional
capabilities
NULL
//
Reserved
);
if
(FAILED(hres))
{
cout
<<
"Failed
to
initialize
security.
Error
code
=
0x"
<<
hex
<<
hres
<<
endl;
CoUninitialize();
return
1;
//
Program
has
failed.
}
//
Step
3:
---------------------------------------------------
//
Obtain
the
initial
locator
to
WMI
-------------------------
IWbemLocator
*pLoc
=
NULL;
hres
=
CoCreateInstance(
CLSID_WbemLocator,
0,
CLSCTX_INPROC_SERVER,
IID_IWbemLocator,
(LPVOID
*)
&pLoc);
if
(FAILED(hres))
{
cout
<<
"Failed
to
create
IWbemLocator
object."
<<
"
Err
code
=
0x"
<<
hex
<<
hres
<<
endl;
CoUninitialize();
return
1;
//
Program
has
failed.
}
//
Step
4:
-----------------------------------------------------
//
Connect
to
WMI
through
the
IWbemLocator::ConnectServer
method
IWbemServices
*pSvc
=
NULL;
//
Connect
to
the
root\cimv2
namespace
with
//
the
current
user
and
obtain
pointer
pSvc
//
to
make
IWbemServices
calls.
hres
=
pLoc->ConnectServer(
_bstr_t(L"ROOT\\CIMV2"),
//
Object
path
of
WMI
namespace
NULL,
//
User
name.
NULL
=
current
user
NULL,
//
User
password.
NULL
=
current
0,
//
Locale.
NULL
indicates
current
NULL,
//
Security
flags.
0,
//
Authority
(e.g.
Kerberos)
0,
//
Context
object
&pSvc
//
pointer
to
IWbemServices
proxy
);
if
(FAILED(hres))
{
cout
<<
"Could
not
connect.
Error
code
=
0x"
<<
hex
<<
hres
<<
endl;
pLoc->Release();
CoUninitialize();
return
1;
//
Program
has
failed.
}
cout
<<
"Connected
to
ROOT\\CIMV2
WMI
namespace"
<<
endl;
//
Step
5:
--------------------------------------------------
//
Set
security
levels
on
the
proxy
-------------------------
hres
=
CoSetProxyBlanket(
pSvc,
//
Indicates
the
proxy
to
set
RPC_C_AUTHN_WINNT,
//
RPC_C_AUTHN_xxx
RPC_C_AUTHZ_NONE,
//
RPC_C_AUTHZ_xxx
NULL,
//
Server
principal
name
RPC_C_AUTHN_LEVEL_CALL,
//
RPC_C_AUTHN_LEVEL_xxx
RPC_C_IMP_LEVEL_IMPERSONATE,
//
RPC_C_IMP_LEVEL_xxx
NULL,
//
client
identity
EOAC_NONE
//
proxy
capabilities
);
if
(FAILED(hres))
{
cout
<<
"Could
not
set
proxy
blanket.
Error
code
=
0x"
<<
hex
<<
hres
<<
endl;
pSvc->Release();
pLoc->Release();
CoUninitialize();
return
1;
//
Program
has
failed.
}
//
Step
6:
--------------------------------------------------
//
Use
the
IWbemServices
pointer
to
make
requests
of
WMI
----
//
For
example,
get
the
name
of
the
operating
system
IEnumWbemClassObject*
pEnumerator
=
NULL;
hres
=
pSvc->ExecQuery(
bstr_t("WQL"),
bstr_t("SELECT
*
FROM
Win32_PhysicalMedia"),
WBEM_FLAG_FORWARD_ONLY
|
WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&pEnumerator);
if
(FAILED(hres))
{
cout
<<
"Query
for
physical
media
failed."
<<
"
Error
code
=
0x"
<<
hex
<<
hres
<<
endl;
pSvc->Release();
pLoc->Release();
CoUninitialize();
return
1;
//
Program
has
failed.
}
//
Step
7:
-------------------------------------------------
//
Get
the
data
from
the
query
in
step
6
-------------------
IWbemClassObject
*pclsObj;
ULONG
uReturn
=
0;
while
(pEnumerator)
{
HRESULT
hr
=
pEnumerator->Next(WBEM_INFINITE,
1,
&pclsObj,
&uReturn);
if(0
==
uReturn)
{
break;
}
VARIANT
vtProp;
//
Get
the
value
of
the
Name
property
hr
=
pclsObj->Get(L"SerialNumber",
0,
&vtProp,
0,
0);
wcout
<<
"Serial
Number
:
"
<<
vtProp.bstrVal
<<
endl;
VariantClear(&vtProp);
}
//
Cleanup
//
========
pSvc->Release();
pLoc->Release();
pEnumerator->Release();
pclsObj->Release();
CoUninitialize();
return
0;
//
Program
successfully
completed.
}
G. 电脑硬盘序列号怎么查询
1、按Win+R打开运行,输入cmd,回车;
H. 怎样查看硬盘序列号
查看硬盘序列号方法,操作方法如下。
1、首先进入系统按Win+R打开运行面板,输入cmd按回车键。
I. VC++怎么获取计算机的机器码
你可以用在渗败VC++中获取这些编号,并用一型凳定的算法将他们组合后,就生成了一个机器码,用这个机器码按照一定的算法生成一个注册码,这样就对你的软丛租颤件进行了保护,使得只有拥有这个机器码的机器才能安装你的软件。 获取硬盘序列号的方法如下(代码) 以驱动器C为例: char m_Volume[256];//卷标名 char m_FileSysName[256]; DWORD m_SerialNum;//序列号 DWORD m_FileNameLength; DWORD m_FileSysFlag; ::GetVolumeInformation(c:\\, m_Volume, 256, &m_SerialNum, &m_FileNameLength, &m_FileSysFlag, 256);执行该函数后,m_Volume就是卷标名字符串,m_SerialNum就是序列号