BCB2010,給點代碼吧!謝謝!
uj5u.com熱心網友回復:
我記得這在網上一大堆,隨便搜都有,我當初存了一些,挑個讀注冊表的給你吧!我是BCB6,BCB2010你自己試試..
順便附上CSDN收藏帖,應有盡有阿!
http://bbs.csdn.net/topics/50472441
//--- CPU Name + Network Card -----------------------
TRegistry *regCPUName = new TRegistry;
TRegistry *regNetName = new TRegistry;
String strCPUName, strNetName;
try{
regCPUName -> RootKey = HKEY_LOCAL_MACHINE;
regCPUName -> OpenKey("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0",false);
strCPUName = regCPUName -> ReadString("ProcessorNameString");
regNetName -> RootKey = HKEY_LOCAL_MACHINE;
regNetName -> OpenKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\NetworkCards\\8",false);
strNetName = regNetName -> ReadString("Description");
WORD wVersionRequested = MAKEWORD(1,1);
WSADATA wsaData;
WSAStartup(wVersionRequested, &wsaData);
hostent *p;
char s[128];
char *p2;
gethostname(s,128);
p = gethostbyname(s);
p2 = inet_ntoa(*((in_addr *)p->h_addr));
WSACleanup();
Memo1 -> Lines -> Add("CPU : " + strCPUName);
Memo1 -> Lines -> Add("NetCard : " + strNetName);
Memo1 -> Lines -> Add("Net IP : " + String(p2));
} __finally{
delete regCPUName;
}
//--- HDD LogicalDrivesID ---------------------------
DWORD Drives = ::GetLogicalDrives();
for(int x = 0;x < 32; x++)
if(Drives &(1 << x))
{
String fs;
String Drive = AnsiString(char('A'+x))+":\\";
DWORD sn, fsf;
char Volume[80],snb[80],fsfb[80];
if(::GetVolumeInformation(Drive.c_str(), Volume,
sizeof(Volume), &sn, 0, &fsf, fsfb, sizeof(fsfb)))
sprintf(snb,"%X",sn);
Memo1 -> Lines -> Add(String(Volume));
Memo1 -> Lines -> Add(String(snb));
Memo1 -> Lines -> Add(String(fsfb));
}
uj5u.com熱心網友回復:
我整理的類,用匯編取CPU資訊,包括CPU名字、型別和速度
#include "classCPUInfo.h" // 取CPU資訊
// #include "classCPUInfo.cpp" // 取CPU資訊
#ifndef _classCPUInfo_cpp_
#define _classCPUInfo_cpp_
/*
www.plm.hk
*/
//-----------------------------------------------------------------
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
classCCPUInfo::classCCPUInfo()
{
cpuname=new char[128];
temp=new char[128];
char OEMString[13];
//OEMString=new char[13];
int iEAXValue,iEBXValue,iECXValue,iEDXValue;
//獲取CPU的品牌:
_asm
{
mov eax,0
cpuid
mov DWORD PTR OEMString,ebx
mov DWORD PTR OEMString+4,edx
mov DWORD PTR OEMString+8,ecx
mov BYTE PTR OEMString+12,0
}
Name=new char[15];
strcpy(Name,OEMString);
// 更多CPU資訊:
_asm
{
mov eax,1
cpuid
mov iEAXValue,eax
mov iEBXValue,ebx
mov iECXValue,ecx
mov iEDXValue,edx
}
MMX=bool(iEDXValue & 0x800000);
iFamily=(0xf00 & iEAXValue)>>8;
FPU=bool(iEDXValue & 0x1);
//H_DMAT(); // 取得CPU資訊,速度稍慢
}
classCCPUInfo::~classCCPUInfo()
{
delete []Name;
delete []cpuname;
delete []temp;
//delete []OEMString;
}
int classCCPUInfo::GetSpeed()
{
int PriorityClass, Priority;
HANDLE hThread,hProcess;
hThread=GetCurrentThread();
hProcess=GetCurrentProcess();
PriorityClass = GetPriorityClass(hProcess);
Priority = GetThreadPriority(hThread);
SetPriorityClass(hProcess, REALTIME_PRIORITY_CLASS);
SetThreadPriority(hThread,THREAD_PRIORITY_TIME_CRITICAL);
long lEAXValue,lEDXValue;
SleepEx(50,false);
_asm
{
xor eax,eax
rdtsc
mov lEAXValue,eax
mov lEDXValue,edx
}
if(SleepEx(500,false)==0)
{
_asm
{
xor eax,eax
rdtsc
sub eax,lEAXValue
sbb edx,lEDXValue
mov lEAXValue, eax
mov lEDXValue, edx
}
}
SetThreadPriority(hThread, Priority);
SetPriorityClass(hProcess, PriorityClass);
return lEAXValue/(1000.0*500);
}
bool classCCPUInfo::withMMX()
{
return MMX;
}
int classCCPUInfo::GetFamily()
{
return iFamily;
}
int classCCPUInfo::GetName(char *name)
{
if(name==NULL) return -1;
strcpy(name,Name);
return 0;
}
int classCCPUInfo::GetTypeName(char *type)
{
// EAX的8到11位表明是幾86:
// 3 - 386
// 4 - i486
// 5 - Pentium
// 6 - Pentium Pro Pentium II
// 2 - Dual Processors
if(type==NULL) return -1;
switch(iFamily)
{
case 2: strcpy(type,"Dual Processors");break;
case 3: strcpy(type,"386");break;
case 4: strcpy(type,"486");break;
case 5: strcpy(type,"Pentium");break;
case 6: strcpy(type,"P2/3,celeron,PPro");break;
case 15: strcpy(type,"P4,P4Celeron");break;
default: strcpy(type,"Unknown Type");
}
return 0;
}
bool classCCPUInfo::hasFPU()
{
return FPU;
}
void classCCPUInfo::H_DMAT(){ // 取得CPU資訊,速度稍慢
memset(cpuname,'\0',128);
memset(temp,'\0',128);
GetName(cpuname);
C_OPHS=String(cpuname); // cpu名字
C_AYUQ=GetSpeed(); // 速度
GetTypeName(temp);
C_XLNA=String(temp); // 型別
C_CFGY=hasFPU(); // HasFPU
C_RBZA=withMMX(); // WithMMX
}
#endif
/*
#include "classCPUInfo.h" // 取CPU資訊
classCCPUInfo * F_HEFM; // 取CPU資訊
void __fastcall TForm1::FormCreate(TObject *Sender)
{
F_HEFM=new classCCPUInfo(); // 取CPU資訊
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
delete F_HEFM; // 取CPU資訊
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
F_HEFM->H_DMAT(); // 取得CPU資訊,速度稍慢
Edit1->Text=F_HEFM->C_OPHS; // cpu名字
Edit2->Text=F_HEFM->C_AYUQ; // 速度
Edit3->Text=F_HEFM->C_XLNA; // 型別
CheckBox1->Checked=F_HEFM->C_CFGY; // HasFPU
CheckBox2->Checked=F_HEFM->C_RBZA; // WithMMX
}
*/
uj5u.com熱心網友回復:
// #include "classCPUInfo.h" // 取CPU資訊
#ifndef _classCPUInfo_H_
#define _classCPUInfo_H_
//-----------------------------------------------------------------
// CPUInfo.h
// by kkm1982
// C++Builder 6,C++Builder 2010,C++Builder XE下直接運行
//----------------------------------------------------------------
class classCCPUInfo
{
private: // 私有的,private則說明其后的識別符號除了類的成員函式之外,用戶定義的其實體不能參考
bool FPU;
char * Name;
bool MMX;
int iFamily;
char * cpuname;
char * temp;
//char * OEMString;
public: // 公有的,public意味著其后的識別符號可以被用戶定義的其實體參考
//---------------------------------------------------------------------------
String C_OPHS; // cpu名字
int C_AYUQ; // 速度
String C_XLNA; // 型別
bool C_CFGY; // HasFPU
bool C_RBZA; // WithMMX
//---------------------------------------------------------------------------
int GetTypeName(char *type);
int GetName(char *name);
int GetFamily();
bool withMMX();
bool hasFPU();
int GetSpeed();
classCCPUInfo();
virtual ~classCCPUInfo();
void H_DMAT(); // 取得CPU資訊,速度稍慢
};
#endif
uj5u.com熱心網友回復:
這個問題你搜一下就有了,何必白送100分
uj5u.com熱心網友回復:
用Victor大佬的代碼http://www.cppfans.com/articles/system/bcb_wmi.asp
uj5u.com熱心網友回復:
① 初始化 COM 介面:
訪問 WMI, 必須先初始化 COM 介面, 在程式的一開始呼叫 CoInitialize(NULL); 初始化, 在結束時呼叫 CoUninitialize(); 釋放資源。
這兩個函式在 #include <comdef.h> 里面定義。
② 獲取訪問 WMI 權限:
CoInitializeSecurity(NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_PKT, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, 0);
如果這個函式回傳 S_OK 獲取權限成功, 否則為失敗。
③ 通過 IWbemLocator 和 IWbemServices 這兩個 COM 介面訪問 WMI, 獲取系統資訊:
這個函式的引數: lpList 回傳資訊, wsClass 為要查找的系統資訊類, 這些 COM 介面在 #include <wbemidl.h> 里定義。
void GetWmiInfo(TStrings *lpList, WideString wsClass)
{
IWbemLocator *pWbemLocator = NULL;
if(CoCreateInstance(CLSID_WbemAdministrativeLocator, NULL, CLSCTX_INPROC_SERVER|CLSCTX_LOCAL_SERVER, IID_IUnknown, (void**)&pWbemLocator) == S_OK)
{
IWbemServices *pWbemServices = NULL;
WideString wsNamespace = (L"root\\cimv2");
if(pWbemLocator->ConnectServer(wsNamespace, NULL, NULL, NULL, 0, NULL, NULL, &pWbemServices) == S_OK)
{
IEnumWbemClassObject *pEnumClassObject = NULL;
WideString wsWQL=L"WQL", wsQuery=WideString(L"Select * from ")+wsClass;
if(pWbemServices->ExecQuery(wsWQL, wsQuery, WBEM_FLAG_RETURN_IMMEDIATELY,NULL, &pEnumClassObject) == S_OK)
{
IWbemClassObject *pClassObject = NULL;
ULONG uCount = 1, uReturned;
if(pEnumClassObject->Reset() == S_OK)
{
int iEnumIdx = 0;
while(pEnumClassObject->Next(WBEM_INFINITE, uCount, &pClassObject, &uReturned) == S_OK)
{
lpList->Add("---------------- ["+IntToStr(iEnumIdx)+"] -----------------");
SAFEARRAY *pvNames = NULL;
if(pClassObject->GetNames(NULL, WBEM_FLAG_ALWAYS | WBEM_MASK_CONDITION_ORIGIN, NULL, &pvNames) == S_OK)
{
long vbl, vbu;
SafeArrayGetLBound(pvNames, 1, &vbl);
SafeArrayGetUBound(pvNames, 1, &vbu);
for(long idx=vbl; idx<=vbu; idx++)
{
long aidx = idx;
wchar_t *wsName = 0;
VARIANT vValue;
VariantInit(&vValue);
SafeArrayGetElement(pvNames, &aidx, &wsName);
BSTR bs = SysAllocString(wsName);
HRESULT hRes = pClassObject->Get(bs, 0, &vValue, NULL, 0);
SysFreeString(bs);
if(hRes == S_OK)
{
AnsiString s;
Variant v = *(Variant*)&vValue;
if(v.IsArray())
{
for(int i=v.ArrayLowBound(); i<=v.ArrayHighBound(); i++)
{
Variant a = v.GetElement(i);
if(!s.IsEmpty())
s+=", ";
s+=VarToStr(a);
}
}
else
{
s = VarToStr(v);
}
lpList->Add(AnsiString(wsName)+"="+s);
}
VariantClear(&vValue);
SysFreeString(wsName);
}
}
if(pvNames)SafeArrayDestroy(pvNames);
iEnumIdx++;
}
}
if(pClassObject)pClassObject->Release();
}
if(pEnumClassObject)pEnumClassObject->Release();
}
if(pWbemServices)pWbemServices->Release();
}
if(pWbemLocator)pWbemLocator->Release();
}
//---------------------------------------------------------------------------
// 通過 WIN32_bios 獲取 BIOS 資訊:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Memo1->Lines->Add("================== [WIN32_bios] =================");
GetWmiInfo(Memo1->Lines, "WIN32_bios");
Memo1->Lines->Add("");
}
--------------------------------------------------------------------------------
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/130015.html
標籤:基礎類
上一篇:快幫我啊
下一篇:具體c++跟c語言有啥區別
