/* wmem.c - Despliega estadisticas sobre el uso de la memoria Copyright (C) 2002 Luis C. Castro Skertchly This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* Cambios 1.0 - Version inicial 1.1 - Se cambio el codigo para mostrar informacion de procesadores Pentium */ #define _CRT_SECURE_NO_DEPRECATE #define _WIN32_WINNT 0x0501 #define WIN32_LEAN_AND_MEAN #include #include #include #include "luislib.h" char sb[256]; OSVERSIONINFO osvi; int GetProcSpeed() { LONG result; HKEY hKey; DWORD data; DWORD dataSize; result = RegOpenKeyEx (HKEY_LOCAL_MACHINE, "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", 0, KEY_QUERY_VALUE, &hKey); if (result == ERROR_SUCCESS) { result = RegQueryValueEx (hKey, "~MHz", NULL, NULL, (LPBYTE)&data, &dataSize); } else { RegCloseKey (hKey); return -1; } RegCloseKey (hKey); return (int)data; } int main(int argc, char **argv) { SYSTEM_INFO si; MEMORYSTATUS ms; char szWinDir[MAX_PATH]; char szSysDir[MAX_PATH]; char temp[128]; if (argc > 1) { if (!lstrcmpi(argv[1], "/?")) { printf("WMEM 1.1 - Show memory usage statics\n" "Copyright (C) 1999-2003, Luis C. Castro Skertchly (lc_castro@yahoo.com)\n" "Usage: wmem\n\n"); return 1; } } memset(&osvi, 0, sizeof(OSVERSIONINFO)); osvi.dwOSVersionInfoSize = sizeof(osvi); if (!GetVersionEx(&osvi)) { PutError("GetVersioEx()", NULL); return 1; } ms.dwLength = sizeof(ms); GetSystemInfo(&si); GlobalMemoryStatus(&ms); GetWindowsDirectory(szWinDir, sizeof(szWinDir)); GetSystemDirectory(szSysDir, sizeof(szSysDir)); printf("%d%% Memory utilization\n", ms.dwMemoryLoad); printf("Total physical memory: %s Kb\n", NumericGeneral(ms.dwTotalPhys / 1024, temp)); printf("Phys. memory available: %s Kb\n", NumericGeneral(ms.dwAvailPhys / 1024, temp)); printf("Page file size: %s Kb\n", NumericGeneral(ms.dwTotalPageFile / 1024, temp)); printf("Available in page file: %s Kb\n", NumericGeneral(ms.dwAvailPageFile / 1024, temp)); printf("Virtual Memory size: %s Kb\n", NumericGeneral(ms.dwTotalVirtual / 1024, temp)); printf("Free Virtual Memory: %s Kb\n", NumericGeneral(ms.dwAvailVirtual / 1024, temp)); printf("Page size: %s bytes\n", NumericGeneral(si.dwPageSize, temp)); printf("Minimum Appl. Address: 0x%08x\n", si.lpMinimumApplicationAddress); printf("Maximum Appl. Address: 0x%08x\n", si.lpMaximumApplicationAddress); printf("Number of processors: %15d\n", si.dwNumberOfProcessors); printf("Allocation Granularity: %s bytes\n", NumericGeneral(si.dwAllocationGranularity, temp)); strcpy(sb, "Processor: "); if (osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) { // Windows 95/98 switch(si.dwProcessorType) { case PROCESSOR_INTEL_386: strcat(sb, "Intel 386"); break; case PROCESSOR_INTEL_486: strcat(sb, "Intel 486"); break; case PROCESSOR_INTEL_PENTIUM: strcat(sb, "Intel Pentium"); break; default: strcat(sb, "Unknown"); } } else { // Windows NT switch(si.wProcessorArchitecture) { case PROCESSOR_ARCHITECTURE_INTEL: strcat(sb, "Intel "); switch(si.wProcessorLevel) { case 3: case 4: wsprintf(temp, "80%d86", si.wProcessorLevel); strcat(sb, temp); if ((si.wProcessorRevision & 0xFF00) == 0xFF00) { wsprintf(temp, " Model %d Stepping %d", (si.wProcessorRevision & 0x00F0) - 0xA, si.wProcessorRevision & 0x000F); strcat(sb, temp); } else { wsprintf(temp, " Stepping %c%02x", HIBYTE(si.wProcessorRevision) + 'A', si.wProcessorRevision & 0x00FF); strcat(sb, temp); } break; default: wsprintf(temp, " %d MHz Pentium Family %d Model %d Stepping %d", GetProcSpeed(), si.wProcessorLevel, HIBYTE(si.wProcessorRevision), LOBYTE(si.wProcessorRevision)); strcat(sb, temp); break; } break; case PROCESSOR_ARCHITECTURE_MIPS: strcat(sb, "MIPS "); switch(si.wProcessorLevel) { case 4: wsprintf(temp, "R400 Revision %d", si.wProcessorRevision); strcat(sb, temp); break; default: strcat(sb, "Unknown"); break; } break; case PROCESSOR_ARCHITECTURE_ALPHA: strcat(sb, "Alpha "); switch(si.wProcessorLevel) { case 21064: strcat(sb, "21064"); break; case 21066: strcat(sb, "21066"); break; case 21164: strcat(sb, "21164"); break; default: strcat(sb, "Unknown"); break; } wsprintf(temp, " Model %c, Pass %02x", HIWORD(si.wProcessorRevision), LOWORD(si.wProcessorRevision)); strcat(sb, temp); break; case PROCESSOR_ARCHITECTURE_PPC: strcat(sb, "PowerPC"); switch(si.wProcessorLevel) { case 1: strcat(sb, "601"); break; case 3: strcat(sb, "603"); break; case 4: strcat(sb, "604"); break; case 6: strcat(sb, "603+"); break; case 9: strcat(sb, "604+"); break; case 20: strcat(sb,"620"); break; default: strcat(sb, "Unknown"); break; } wsprintf(temp, " %02x.%02x", HIWORD(si.wProcessorRevision), LOWORD(si.wProcessorRevision)); strcat(sb, temp); break; case PROCESSOR_ARCHITECTURE_UNKNOWN: strcat(sb, "Unknown"); break; } } puts(sb); printf("%s is Windows directory\n", szWinDir); printf("%s is System directory\n", szSysDir); return 0; }