13,825
社区成员
发帖
与我相关
我的任务
分享
//---------------------------------------------------------------------------
#ifndef MainFormH
#define MainFormH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <Buttons.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TGroupBox *GroupBox1;
TLabel *Label1;
TEdit *Edit1;
TLabel *Label2;
TLabel *Label3;
TLabel *Label4;
TLabel *Label5;
TEdit *Edit2;
TEdit *Edit3;
TEdit *Edit4;
TEdit *Edit5;
TBitBtn *BitBtn1;
TBitBtn *BitBtn2;
void __fastcall BitBtn2Click(TObject *Sender);
void __fastcall BitBtn1Click(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "MainForm.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
this->Edit1->Text="";
this->Edit2->Text="";
this->Edit3->Text="";
this->Edit4->Text="";
this->Edit5->Text="";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn2Click(TObject *Sender)
{
this->Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
SYSTEM_INFO si;
GetSystemInfo(&si);
this->Edit1->Text=IntToStr(si.dwPageSize);
this->Edit2->Text=IntToStr(Integer(si.lpMinimumApplicationAddress));
this->Edit3->Text=IntToStr(Integer(si.lpMaximumApplicationAddress));
this->Edit4->Text=IntToStr(si.dwNumberOfProcessors);
switch(si.dwProcessorType)
{
case 386:
case 486:
this->Edit5->Text="Intel 80"+IntToStr(si.dwProcessorType);
break;
case 586:
this->Edit5->Text="Intel Pentium"+IntToStr(si.dwProcessorType);
break;
default:
this->Edit5->Text="非Intel处理器";
}
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
#ifndef MainFormH
#define MainFormH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <Buttons.hpp>
#include <FileCtrl.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TGroupBox *GroupBox1;
TLabel *Label1;
TDriveComboBox *DriveComboBox1;
TBitBtn *BitBtn1;
TLabel *Label2;
TLabel *Label3;
TLabel *Label4;
TEdit *Edit1;
TEdit *Edit2;
TEdit *Edit3;
void __fastcall BitBtn1Click(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "MainForm.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
this->Edit1->Text="";
this->Edit2->Text="";
this->Edit3->Text="";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
char cDrive=this->DriveComboBox1->Drive;
AnsiString StrDrive=cDrive;
StrDrive+=":";
char VolName[200],FSName[50];
DWORD dwVolSer,lpMaxComLen,lpFSFlags;
if( GetVolumeInformation(StrDrive.c_str(),VolName,200,&dwVolSer,&lpMaxComLen,&lpFSFlags,FSName,50))
{
if(dwVolSer==0)
this->Edit1->Text="";
else
this->Edit1->Text=IntToStr(Integer(dwVolSer));;
this->Edit2->Text=VolName;
this->Edit3->Text=FSName;
}
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Memo1->Lines->Clear(); //清空内容
//显示WMI所有所能显示的硬件信息
for(int i = 0 ; AllWmiClasses[i] ; i++)
{
Memo1->Lines->Add("========================= [" + AnsiString(AllWmiClasses[i]) + "] ==============================");
GetWmiInfo(Memo1->Lines,AllWmiClasses[i]);
Memo1->Lines->Add("");
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
//初始化COM接口
CoInitialize(NULL);
//获取访问WMI权限
if(CoInitializeSecurity(NULL,-1,NULL,NULL,RPC_C_AUTHN_LEVEL_PKT,RPC_C_IMP_LEVEL_IMPERSONATE,NULL,EOAC_NONE,0) != S_OK)
{ //如果获取失败
ShowMessage("无法获取权限!");
Application->Terminate();
}
//初始化Memo组件
Memo1->Clear(); //清空内容
//设置字体
Font->Name = "宋体";
Font->Charset = GB2312_CHARSET;
Font->Size = 9;
}
//----------------------------------------------------------------------
//---------------------------------------------------------------------------
#include <vcl.h>
#include <comdef.h>
#include <wbemidl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
//WMI可以访问的硬件信息类型
static char *AllWmiClasses[] =
{
"Win32_1394Controller" ,
"Win32_BaseBoard" ,
"Win32_Battery" ,
"Win32_BIOS" ,
"Win32_Bus" ,
"Win32_CacheMemory" ,
"Win32_CDROMDrive" ,
"Win32_CurrentProbe" ,
"Win32_DesktopMonitor" ,
"Win32_DeviceMemoryAddress" ,
"Win32_DiskDrive" ,
"Win32_DisplayConfiguration" ,
"Win32_DisplayControllerConfiguration",
"Win32_DMAChannel" ,
"Win32_Fan" ,
"Win32_FloppyController" ,
"Win32_FloppyDrive" ,
"Win32_HeatPipe" ,
"Win32_IDEController" ,
"Win32_InfraredDevice" ,
"Win32_IRQResource" ,
"Win32_Keyboard" ,
"Win32_MemoryArray" ,
"Win32_MemoryDevice" ,
"Win32_MotherboardDevice" ,
"Win32_NetworkAdapter" ,
"Win32_NetworkAdapterConfiguration" ,
"Win32_OnBoardDevice" ,
"Win32_ParallelPort" ,
"Win32_PCMCIAController" ,
"Win32_PhysicalMemory" ,
"Win32_PhysicalMemoryArray" ,
"Win32_PnPEntity" ,
"Win32_PointingDevice" ,
"Win32_PortableBattery" ,
"Win32_PortConnector" ,
"Win32_PortResource" ,
"Win32_POTSModem" ,
"Win32_PowerManagementEvent" ,
"Win32_Printer" ,
"Win32_PrinterConfiguration" ,
"Win32_PrintJob" ,
"Win32_Processor" ,
"Win32_Refrigeration" ,
"Win32_SerialPort" ,
"Win32_SerialPortConfiguration" ,
"Win32_SMBIOSMemory" ,
"Win32_SoundDevice" ,
"Win32_SystemEnclosure" ,
"Win32_SystemMemoryResource" ,
"Win32_SystemSlot" ,
"Win32_TapeDrive" ,
"Win32_TemperatureProbe" ,
"Win32_UninterruptiblePowerSupply" ,
"Win32_USBController" ,
"Win32_VideoConfiguration" ,
"Win32_VideoController" ,
"Win32_VoltageProbe" ,
NULL
};
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
__fastcall TForm1::~TForm1()
{
CoUninitialize(); //释放资源
}
//---------------------------------------------------------------------------
void GetWmiInfo(TStrings *lpList, WideString wsClass)
{
//通过IWbemLocator和IWbemServices这两个COM接口访问 WMI, 获取系统信息
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();
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
//---------------------------------------------------------------------------
USEFORM("Unit1.cpp", Form1);
//---------------------------------------------------------------------------
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
try
{
Application->Initialize();
Application->CreateForm(__classid(TForm1), &Form1);
Application->Run();
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
catch (...)
{
try
{
throw Exception("");
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
}
return 0;
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TMemo *Memo1; //多行文本编辑器
TButton *Button1; //显示所有硬件信息的按钮
void __fastcall Button1Click(TObject *Sender);
void __fastcall FormCreate(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
__fastcall ~TForm1();
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif