當前位置:首頁 » 硬碟大全 » 獲取硬碟序列號vc
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

獲取硬碟序列號vc

發布時間: 2023-05-11 07:51:11

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就是序列號