000
18.03.2003, 18:28 Uhr
Bruder Leif
dances with systems (Operator)
|
Ein kleines Beispielprogramm für alle, die unter Windoof Daten über das System abfragen wollen. Sollte eigentlich alles selbsterklärend sein, das Programm fragt den Prozessortyp und Taktfrequenz, Speichergröße, Computername, OS, Laufwerke und die installierten Drucker ab. Wenn noch was unklar ist, schreib ich vielleicht auch mal nen längeren Text dazu... *g*
C++: |
// Die Assembler-Teile müssen ggf. compilerspezifisch angepasst werden... #define CPUID DB 0x0F, 0xA2 #define RDTSC DB 0x0F, 0x31
//##############################################################################
#include <stdio.h> #include <string.h> #include <iostream> #include <windows.h>
using namespace std;
//##############################################################################
long GetCpuSpeed(void) { SYSTEM_INFO SysInf; DWORD start_high, start_low, overhead_high, overhead_low, MHz;
GetSystemInfo(&SysInf); if(SysInf.wProcessorLevel<5) return 0; // RDTSC gibts erst ab Pentium!
MHz = 100000;
_asm { RDTSC MOV overhead_low, EAX MOV overhead_high, EDX RDTSC SUB EAX, overhead_low SBB EDX, overhead_high MOV overhead_low, EAX MOV overhead_high, EDX RDTSC MOV start_low, EAX MOV start_high, EDX } Sleep(100); _asm { RDTSC SUB EAX, overhead_low SBB EDX, overhead_high SUB EAX, start_low SBB EDX, start_high DIV MHz MOV MHz, EAX } return MHz; }
//##############################################################################
void System() { OSVERSIONINFO VersInf; DWORD dwEAX, dwEBX, dwECX, dwEDX, dwBuffer = 511; WORD wTyp, wFamilie, wModell; char szBuffer[512], szVendor[16]; MEMORYSTATUS MemState; HDC hdcDesktop; int iCpuSpeed;
cout << "[System]" << endl;
cout << "OS "; VersInf.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); GetVersionEx(&VersInf);
if(VersInf.dwPlatformId == VER_PLATFORM_WIN32_NT) { if(VersInf.dwMajorVersion == 5) { if(VersInf.dwMinorVersion == 0) cout << "Windows 2000"; if(VersInf.dwMinorVersion == 1) cout << "Windows XP"; } else cout << "Windows NT"; } else if(VersInf.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) { cout << "Windows 95/98/ME"; }
cout << " " << VersInf.dwMajorVersion << "." << VersInf.dwMinorVersion << "." << VersInf.dwBuildNumber; cout << " " << VersInf.szCSDVersion << endl;
cout << "CPU ";
_asm { XOR EAX, EAX CPUID MOV dwEBX, EBX MOV dwECX, ECX MOV dwEDX, EDX MOV EAX, 1 CPUID MOV dwEAX, EAX }
szVendor[0] = LOBYTE(LOWORD(dwEBX)); szVendor[1] = HIBYTE(LOWORD(dwEBX)); szVendor[2] = LOBYTE(HIWORD(dwEBX)); szVendor[3] = HIBYTE(HIWORD(dwEBX)); szVendor[4] = LOBYTE(LOWORD(dwEDX)); szVendor[5] = HIBYTE(LOWORD(dwEDX)); szVendor[6] = LOBYTE(HIWORD(dwEDX)); szVendor[7] = HIBYTE(HIWORD(dwEDX)); szVendor[8] = LOBYTE(LOWORD(dwECX)); szVendor[9] = HIBYTE(LOWORD(dwECX)); szVendor[10] = LOBYTE(HIWORD(dwECX)); szVendor[11] = HIBYTE(HIWORD(dwECX)); szVendor[12] = 0x00; cout << szVendor;
wTyp = (dwEAX >> 12) & 3; wFamilie = (dwEAX >> 8) & 15; wModell = (dwEAX >> 4) & 15;
if(!strcmp(szVendor, "GenuineIntel")) { char szTyp[4][16]={"", " Overdrive", "Dual"}; char szFam5[16][32]={"P5 Prototyp", "Pentium", "Pentium", "Pentium (486 OD)", "Pentium MMX"}; char szFam6[16][16]={"P6 Prototyp", "Pentium Pro", "", "Pentium II", "", "Pentium II", "Celeron A", "Pentium III", "Pentium III", "", "Xeon"}; cout << " ";
switch(wFamilie) { case 4: cout << "80486"; break; case 5: cout << szFam5[wModell]; break; case 6: cout << szFam6[wModell]; break; case 15: if(wModell == 0) cout << "Pentium 4"; break; } cout << szTyp[wTyp]; } else if(!strcmp(szVendor, "AuthenticAMD")) { char szFam5[16][8]={"K5/M0", "K5/M1", "K5/M2", "K5/M3", "", "", "K6/M6", "K6/M7", "K6-2", "K6-3"}; char szFam6[16][32]={"", "Athlon/M1", "Athlon/M2", "Duron/M3", "Athlon/M4", "", "Athlon MP/XP/Duron, M6", "Duron/M7"}; cout << " ";
switch(wFamilie) { case 4: if(wModell > 13) cout << "5x86"; else cout << "486"; break; case 5: cout << szFam5[wModell]; break; case 6: cout << szFam6[wModell]; break; } }
cout << " (TFM " << wTyp << "/" << wFamilie << "/" << wModell << ")";
// GetCpuSpeed gibt erst ab dem 2. Aufruf den richtigen Wert zurück, warum auch immer... GetCpuSpeed(); iCpuSpeed = GetCpuSpeed(); if(iCpuSpeed < 1000) sprintf(szBuffer, ", %d MHz", iCpuSpeed); else sprintf(szBuffer, ", %.1f GHz", (float) iCpuSpeed / 1000); cout << szBuffer << endl;
// Geht unter Windows nicht wg. Protected Mode // cout << "BIOS-Name: "; try { cout << ((char*) 0xFE061) << endl; } catch(...) { cout << "n/a" << endl; } // cout << "BIOS-Copyright: "; try { cout << ((char*) 0xFE091) << endl; } catch(...) { cout << "n/a" << endl; } // cout << "BIOS-Datum: "; try { cout << ((char*) 0xFFFF5) << endl; } catch(...) { cout << "n/a" << endl; } // cout << "BIOS-Seriennr: "; try { cout << ((char*) 0xFEC71) << endl; } catch(...) { cout << "n/a" << endl; }
cout << "Computername "; GetComputerName(szBuffer, &dwBuffer); cout << szBuffer << endl;
MemState.dwLength = sizeof(MEMORYSTATUS); GlobalMemoryStatus(&MemState); cout << "RAM "; cout << (int) (MemState.dwTotalPhys / 1048576 + 1) << " MB" << endl; cout << "Auslagerungsdatei "; cout << (int) (MemState.dwTotalPageFile / 1048576 + 1) << " MB" << endl;
cout << "Bildschirmaufloesung "; cout << GetSystemMetrics(SM_CXSCREEN) << " * " << GetSystemMetrics(SM_CYSCREEN) << endl;
cout << "Farbtiefe "; hdcDesktop = GetDC(0); cout << GetDeviceCaps(hdcDesktop, BITSPIXEL) << " Bits/Pixel" << endl; ReleaseDC(0, hdcDesktop); }
//##############################################################################
void Laufwerke() { DWORD dwDrives = GetLogicalDrives(); ULARGE_INTEGER nDummy, nTotalBytes, nFreeBytes; int iBytes; char szDrive[8]="A:\\"; char szVolName[80], szFSName[80], szBuffer[80]; bool bQueryVol;
cout << "[Laufwerke]" << endl;
for(int i=0, j=1; i<26; i++, j*=2) { if(dwDrives & j) { szDrive[0] = i + 'A'; cout << szDrive << " "; bQueryVol = false;
switch(GetDriveType(szDrive)) { case DRIVE_UNKNOWN: cout << "Unbekannt"; break; case DRIVE_NO_ROOT_DIR: cout << "? Kein Root-Verzeichnis ?"; break; case DRIVE_REMOVABLE: cout << "Wechseldatentraeger"; bQueryVol = true; break; case DRIVE_FIXED: cout << "Festplatte"; bQueryVol = true; break; case DRIVE_REMOTE: cout << "Netzwerkverknuepfung"; break; case DRIVE_CDROM: cout << "CDROM"; break; case DRIVE_RAMDISK: cout << "RAM-Disk"; bQueryVol = true; break; }
if(bQueryVol) { if(GetDiskFreeSpaceEx(szDrive, &nDummy, &nTotalBytes, &nFreeBytes)) { iBytes = nTotalBytes.QuadPart/1048576; if(iBytes < 1024) sprintf(szBuffer, ", %5d MB Kapazitaet", iBytes); else sprintf(szBuffer, ", %5.1f GB Kapazitaet", (float) iBytes / 1024); cout << szBuffer;
iBytes = nFreeBytes.QuadPart/1048576; if(iBytes < 1024) sprintf(szBuffer, ", %5d MB frei", iBytes); else sprintf(szBuffer, ", %5.1f GB frei", (float) iBytes / 1024); cout << szBuffer; }
if(GetVolumeInformation(szDrive, szVolName, 79, NULL, NULL, NULL, szFSName, 79)) cout << ", " << szFSName; } cout << endl; } } }
//##############################################################################
void Drucker() { PRINTER_INFO_1 paDrucker[32]; DWORD dwDummy, dwCount, i;
cout << "[Drucker, lokal]" << endl; EnumPrinters(PRINTER_ENUM_LOCAL, NULL, 1, (unsigned char*) (&paDrucker[0]), sizeof(paDrucker), &dwDummy, &dwCount);
for(i=0; i<dwCount; i++) cout << paDrucker[ i ].pName << endl;
cout << endl << "[Drucker, Netzwerk]" << endl; EnumPrinters(PRINTER_ENUM_NETWORK, NULL, 1, (unsigned char*) (&paDrucker[0]), sizeof(paDrucker), &dwDummy, &dwCount);
for(i=0; i<dwCount; i++) cout << paDrucker[ i ].pName << endl; }
//##############################################################################
int main() { SetErrorMode(SEM_FAILCRITICALERRORS);
System(); cout << endl; Laufwerke(); cout << endl; Drucker(); return 0; }
//##############################################################################
|
-- Mit 40 Fieber sitzt man nicht mehr vor dem PC. Man liegt im Bett. Mit dem Notebook. |