김도완 님이 쓰신 글 :
: 바이오스에 진입해서 cpu 설정등에서 활성화가 가능하고 간단히 명령 라인으로 확인하는 방법은
:
: > wmic cpu get processorid, uniqueid 이렇게 하시면 될겁니다.
:
: > wmic cpu하면 내용이 다 보입니다.
:
: 단일 아이디를 만들 땐 bios 시리얼 번호와 NIC의 MAC을 조합하는게 가장 좋다고 합니다.
:
: > wmic bios 요렇게 하면 바이오스 정보가 다 보입니다.
:
: 성공하시길~
:
:
: LeeD 님이 쓰신 글 :
: : #include <comutil.h>
: : #include <assert.h>
: : //---------------------------------------------------------------------------
: : #pragma link "bcbatl.lib"
: : //---------------------------------------------------------------------------
: : void __stdcall _com_issue_error(long HRESULT) throw(_com_error)
: : {
: : //ATLASSERT(HRESULT);
: : assert(HRESULT); // 본래는 _com_error 객체를 던지는 에러처리를 해야 함.
: : }
: : //---------------------------------------------------------------------------
: :
: : 이렇게 추가하니까 에러는 사라졌네요ㅎ
: :
: : 그런데 첫번째 if문에서 바로 Error1이 뜨네요.
: :
: : 이것도 BIOS에서 시리얼 번호에 대한 기능이 꺼져있어서 그런건가요?
: :
: : 그렇다면 시리얼 번호에대한 기능을 enable하는 법좀 알려주세용
: :
: : 아니면 다른 문제가 있는건가요?ㅜ
: :
: : 그리고 그냥 첫번째 if문 주석걸고 실행해 보았더니 UniqueId 가 NULL값이 나오네요ㅜㅜ
: :
: : LeeD 님이 쓰신 글 :
: : : 김도완님 감사합나디^^
: : :
: : : 제가 사이트에서 예제소스를 보고 작성해 보았는데요. ERROR가 나네요ㅜㅜ
: : :
: : : [ILINK32 Error] Error: Unresolved external '__stdcall _com_issue_error(long)' referenced from C:\USERS\CLONIX\DOCUMENTS\RAD STUDIO\PROJECTS\DEBUG\CPUID2CPP.OBJ
: : : [ILINK32 Error] Error: Unresolved external '__stdcall _com_util::ConvertStringToBSTR(const char *)' referenced from C:\USERS\CLONIX\DOCUMENTS\RAD STUDIO\PROJECTS\DEBUG\CPUID2CPP.OBJ
: : :
: : : 뭔가 잘못된 부분 있나요?ㅜㅜ
: : :
: : : 그리고 혹시 BIOS enable 시키는 법도 알려주시면 감사하겠습니다.ㅠ
: : :
: : : //---------------------------------------------------------------------------
: : :
: : : #include <vcl.h>
: : : #pragma hdrstop
: : :
: : : #include "CPUID2cpp.h"
: : :
: : : #define _WIN32_DCOM
: : : #include <iostream>
: : : #include <comdef.h>
: : : #include <Wbemidl.h>
: : :
: : : #pragma comment(lib, "wbemuuid.lib")
: : :
: : : using namespace std;
: : : //---------------------------------------------------------------------------
: : : #pragma package(smart_init)
: : : #pragma resource "*.dfm"
: : : TMain *Main;
: : : //---------------------------------------------------------------------------
: : : __fastcall TMain::TMain(TComponent* Owner)
: : : : TForm(Owner)
: : : {
: : : }
: : : //---------------------------------------------------------------------------
: : : int GetCpuSerial()
: : : {
: : : HRESULT hres;
: : :
: : : hres = CoInitializeEx(0, COINIT_MULTITHREADED);
: : : if (FAILED(hres))
: : : {
: : : ShowMessage("Error1");
: : : return 1; // Program has failed.
: : : }
: : :
: : : 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))
: : : {
: : : CoUninitialize();
: : : ShowMessage("Error2");
: : : return 1; // Program has failed.
: : : }
: : :
: : : IWbemLocator *pLoc = NULL;
: : :
: : : hres = CoCreateInstance(
: : : CLSID_WbemLocator,
: : : 0,
: : : CLSCTX_INPROC_SERVER,
: : : IID_IWbemLocator, (LPVOID *) &pLoc);
: : :
: : : if (FAILED(hres))
: : : {
: : : CoUninitialize();
: : : ShowMessage("Error3");
: : : return 1; // Program has failed.
: : : }
: : :
: : : IWbemServices *pSvc = NULL;
: : :
: : : 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 (for example, Kerberos)
: : : 0, // Context object
: : : &pSvc // pointer to IWbemServices proxy
: : : );
: : :
: : : if (FAILED(hres))
: : : {
: : : pLoc->Release();
: : : CoUninitialize();
: : : ShowMessage("Error4");
: : : return 1; // Program has failed.
: : : }
: : :
: : : Main->Memo1->Lines->Add("Connected to ROOT\\CIMV2 WMI namespace");
: : :
: : : 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))
: : : {
: : : pSvc->Release();
: : : pLoc->Release();
: : : CoUninitialize();
: : : ShowMessage("Error5");
: : : return 1; // Program has failed.
: : : }
: : :
: : : IEnumWbemClassObject* pEnumerator = NULL;
: : : hres = pSvc->ExecQuery(
: : : bstr_t("WQL"),
: : : bstr_t("SELECT * FROM Win32_OperatingSystem"),
: : : WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
: : : NULL,
: : : &pEnumerator);
: : :
: : : if (FAILED(hres))
: : : {
: : : pSvc->Release();
: : : pLoc->Release();
: : : CoUninitialize();
: : : ShowMessage("Error6");
: : : return 1; // Program has failed.
: : : }
: : :
: : : 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"Name", 0, &vtProp, 0, 0);
: : : // wcout << " OS Name : " << vtProp.bstrVal << endl;
: : : Main->Memo1->Lines->Add(" OS Name : " + (String)vtProp.bstrVal);
: : : VariantClear(&vtProp);
: : :
: : : pclsObj->Release();
: : : }
: : :
: : : pSvc->Release();
: : : pLoc->Release();
: : : pEnumerator->Release();
: : : pclsObj->Release();
: : : CoUninitialize();
: : :
: : : return 0;
: : : }
: : : void __fastcall TMain::Button1Click(TObject *Sender)
: : : {
: : : GetCpuSerial();
: : : }
: : : //---------------------------------------------------------------------------
: : :
: : : 김도완 님이 쓰신 글 :
: : : : 대부분 바이오스에서 시리얼 번호에 대한 기능이 꺼져있다고 합니다. 바이오스에서 enable시킨 후 테스트해보시고,
: : : :
: : : : 다른 방법으로 WMI를 이용하는 방법이 있습니다.
: : : :
: : : : 대충보니 UniqueID라는게 맞는 것 같네요.
: : : :
: : : :
http://msdn.microsoft.com/en-us/library/aa394373.aspx
: : : :
: : : : 참고하시길~
: : : :
: : : :
: : : : LeeD 님이 쓰신 글 :
: : : : : 안녕하세요.^^
: : : : :
: : : : : //---------------------------------------------------------------------------
: : : : : #include <vcl.h>
: : : : : #pragma hdrstop
: : : : :
: : : : : #include "Unit1.h"
: : : : : //---------------------------------------------------------------------------
: : : : : #pragma package(smart_init)
: : : : : #pragma resource "*.dfm"
: : : : : TMain *Main;
: : : : : //---------------------------------------------------------------------------
: : : : : __fastcall TMain::TMain(TComponent* Owner)
: : : : : : TForm(Owner)
: : : : : {
: : : : : }
: : : : : //---------------------------------------------------------------------------
: : : : : #pragma pack(push, 1)
: : : : : struct TCPUID
: : : : : {
: : : : : DWORD Version;
: : : : : DWORD Other;
: : : : : DWORD ExtendedFeatures;
: : : : : DWORD Features;
: : : : : };
: : : : : #pragma pack(pop)
: : : : :
: : : : : #pragma option push -w-
: : : : :
: : : : : void __fastcall CPU_ID(TCPUID* CpuID)
: : : : : {
: : : : : __asm
: : : : : {
: : : : : PUSH EBX
: : : : : PUSH EDI
: : : : : MOV EDI, EAX
: : : : : MOV EAX,1
: : : : : DW 0xA20F
: : : : : STOSD
: : : : : MOV EAX, EBX
: : : : : STOSD
: : : : : MOV EAX, ECX
: : : : : STOSD
: : : : : MOV EAX, EDX
: : : : : STOSD
: : : : : POP EDI
: : : : : POP EBX
: : : : : }
: : : : : }
: : : : :
: : : : : void __fastcall CPU_Serial(unsigned __int64* SerialNumber)
: : : : : {
: : : : : __asm
: : : : : {
: : : : : PUSH EBX
: : : : : PUSH EDI
: : : : : MOV EDI, EAX
: : : : : MOV EAX, 3
: : : : : DW 0xA20F
: : : : : MOV EAX, ECX
: : : : : STOSD
: : : : : MOV EAX, EDX
: : : : : STOSD
: : : : : POP EDI
: : : : : POP EBX
: : : : : }
: : : : : }
: : : : :
: : : : : bool IsCPUIDAvailable(void)
: : : : : {
: : : : : __asm
: : : : : {
: : : : : PUSHFD
: : : : : POP EAX
: : : : : MOV EDX, EAX
: : : : : XOR EAX, 0x00200000
: : : : : PUSH EAX
: : : : : POPFD
: : : : : PUSHFD
: : : : : POP EAX
: : : : : XOR EAX, EDX
: : : : : SHR EAX, 21
: : : : : }
: : : : : }
: : : : :
: : : : : bool GetCPUSerialNumber(unsigned __int64 *SerialNumber)
: : : : : {
: : : : : *SerialNumber = 0;
: : : : : if( IsCPUIDAvailable() )
: : : : : {
: : : : : TCPUID CpuID;
: : : : : memset(&CpuID, 0, sizeof(TCPUID));
: : : : : CPU_ID(&CpuID);
: : : : : if( CpuID.Features & 0x00040000 )
: : : : : {
: : : : : CPU_Serial(SerialNumber);
: : : : : return true;
: : : : : }
: : : : : }
: : : : : return false;
: : : : : }
: : : : :
: : : : : #pragma option pop
: : : : :
: : : : : void __fastcall TMain::Button1Click(TObject *Sender)
: : : : : {
: : : : : unsigned __int64 SerialNumber = 0;
: : : : : if( GetCPUSerialNumber(&SerialNumber))
: : : : : {
: : : : : ShowMessage(SerialNumber);
: : : : : }
: : : : : }
: : : : : //---------------------------------------------------------------------------
: : : : :
: : : : : 제가 CPU Serial번호를 가져오기 위하여 위와 같이 코딩하였는데요.
: : : : :
: : : : : GetCPUSerialNumber(&SerialNumber)의 리턴값이 false가 나오네요.ㅜ
: : : : :
: : : : : 저는 어디가 잘못되었는지 잘 모르겠어요ㅠㅠ
: : : : :
: : : : : 도움 주시면 감사하겠습니다.