hardware information

Discussion in 'C' started by Dyutza, Sep 6, 2007.

  1. Dyutza

    Dyutza New Member

    Joined:
    Sep 6, 2007
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    How can I obtain some hardware information :motherboard Id ,etc from a C/C++ method?
     
  2. bluedragon

    bluedragon New Member

    Joined:
    Sep 17, 2007
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    U will need to read the information on a BIOS ROM

    Different compilers have different headers for this one.

    u will first need to create a handle that would fetch the information

    I don't know much but it must be similar to fetching time from the BIOS
     
  3. Vineel567

    Vineel567 New Member

    Joined:
    Nov 23, 2007
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    hi........

    By default ANSI libraries wont provide to the capability to play with ur hardware........

    the only solution is use operating system functions(like WIN32 api functions)
    Code:
    //------------------------------------------------------------------------
    #include<windows.h>
    #include<tchar.h>
    #include<stdio.h>
    #include<string.h>
    
    #define _UNICODE
    
    void PrintSystemName()
    {
    	TCHAR compName[40];
    	int size=40;
    
    	if(GetComputerName(compName,&size)!=0)
    		_tprintf(_T("\nComputer Name : %s "),compName);
    
    }
    
    void PrintUserName()
    {
    	TCHAR uName[40];
    	int size = 40;
    
    	if(GetUserName(uName,&size) != 0)
    		_tprintf(_T("\nLogged user name : %s"),uName);
    }
    
    void PrintSystemUpTime()
    {
    	unsigned int t,d,h,m,s;
    	t = GetTickCount();
    	t/=1000;
    	d = t/86400;	//days
    	t = t%86400;
    	h = t/3600;
    	t = t%3600;
    	m = t/60;
    	t = t%60;
    	s = t;
    
    	_tprintf(_T("\nSystem Up Time(D:H:M:S) = %u:%u:%u:%u"),d,h,m,s);	
    }
    void PrintDrivesInfo()
    {
    	int drives,i=0;
    	__int64 nFree,nTotal,nHDFree=0,nHDTotal=0;
    	TCHAR dName[40],volName[40];
    
    	_tprintf(_T("\n\nHard Disk Info:"));
    	_tprintf(_T(  "\n---------------"));
    	drives = GetLogicalDrives();
    	while(drives != 0)
    	{
    		if((drives&1) == 1) {
    			wsprintf(dName,_T("%c:\\"),'A'+i);	
    			if(GetDriveType(dName) == DRIVE_FIXED){	
    				if(GetDiskFreeSpaceEx(dName,(PULARGE_INTEGER)&nFree,(PULARGE_INTEGER)&nTotal,NULL)!= 0){
    
    					_tprintf(_T("\n%s"),dName);
    					nHDFree += nFree;
    					nHDTotal += nTotal;	
    					_tprintf(_T(" Free : %6.2I64fGB Total : %6.2I64fGB  "),nFree/(1024*1024*1024.0),nTotal/(1024*1024*1024.0));
    					GetVolumeInformation(dName,NULL,0,NULL,NULL,NULL,volName,10);
    					_tprintf(_T("%s"),volName);
    				}
    			}
    		}
    		drives>>=1;
    		i++;
    	}
    	_tprintf(_T("\n==========================================="));
    	_tprintf(_T("\n    Free : %6.2I64fGB Total : %6.2I64fGB"),nHDFree/(1024*1024*1024.0),nHDTotal/(1024*1024*1024.0));
    	_tprintf(_T("\n==========================================="));
    
    }
    
    void PrintMonitorResolution()
    {
    	int width,height;	
    	width = GetSystemMetrics(SM_CXSCREEN);
    	height = GetSystemMetrics(SM_CYSCREEN);
    	_tprintf(_T("\n\nMonitor Resolution : %dx%d"),width,height);
    }
    
    
    void PrintOSInfo()
    {
    	TCHAR windirName[55];
    	OSVERSIONINFO verInfo={sizeof(OSVERSIONINFO)};
    	_tprintf(_T("\n\nOS Info: "));
    	_tprintf(_T(  "\n--------"));
    	_tprintf(_T("\nVersion : "));
    	GetVersionEx(&verInfo);
    	if(verInfo.dwMajorVersion == 4 && verInfo.dwMinorVersion == 10)_tprintf(_T(" Windows 98 %s"),verInfo.szCSDVersion);
    	if(verInfo.dwMajorVersion == 5 && verInfo.dwMinorVersion == 0)_tprintf(_T(" Windows 2000 %s"),verInfo.szCSDVersion);
    	if(verInfo.dwMajorVersion == 5 && verInfo.dwMinorVersion == 1)_tprintf(_T(" Windows XP %s"),verInfo.szCSDVersion);
    	if(verInfo.dwMajorVersion == 5 && verInfo.dwMinorVersion == 2)_tprintf(_T(" Windows 2003 %s"),verInfo.szCSDVersion);
    
    	GetWindowsDirectory(windirName,55);
    	_tprintf(_T("\nWindows Directory : %s "),windirName);
    
    	GetSystemDirectory(windirName,55);
    	_tprintf(_T("\nSystem Directory  : %s "),windirName);
    }
    
    void PrintProcessorInfo()
    {
    	HKEY hKey,tempKey;//Pointer to HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor
    	TCHAR subKeyName[40],tempKeyName[40],valBuf[100];
    	int i=0,size=100,t;
    
    	_tprintf(_T("\n\nProcessor Info:"));
    	_tprintf(_T(  "\n---------------"));
    	__asm
    	{
    		mov eax,01h		//01h for getting number of core present in the physical processor
    		cpuid
    		mov t,ebx
    	}
    	_tprintf(_T("\nNumber of logical processors(cores) : %d"),(t>>16)&0xff);  
    
    
    	if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,"HARDWARE\\DESCRIPTION\\System\\CentralProcessor",0,KEY_READ,&hKey) == ERROR_SUCCESS)
    	{
    		while(RegEnumKey(hKey,i++,subKeyName,40) != ERROR_NO_MORE_ITEMS){
    			if(RegOpenKeyEx(hKey,subKeyName,0,KEY_READ,&tempKey) == ERROR_SUCCESS)
    			{
    				size = 100;
    				if(RegQueryValueEx(tempKey,_T("ProcessorNameString"),NULL,NULL,valBuf,&size) == ERROR_SUCCESS) 
    					_tprintf(_T("\nProcessor  %s : %s"),subKeyName,valBuf);
    				size = 100;
    				if(RegQueryValueEx(tempKey,_T("Identifier"),NULL,NULL,valBuf,&size) == ERROR_SUCCESS) 
    					_tprintf(_T(" %s"),valBuf);
    				RegCloseKey(tempKey);
    			}
    		}
    		RegCloseKey(hKey);
    	}
    }
    
    void PrintMemoryInfo()
    {
    	MEMORYSTATUSEX ms={sizeof(MEMORYSTATUSEX)};
    	GlobalMemoryStatusEx(&ms);
    
    	_tprintf(_T("\n\nMemory Info:"));
    	_tprintf(_T(  "\n------------"));
    	_tprintf(_T("\nTotal Physical Memory     : %8.2I64fMB \nAvailable Physical Memory : %8.2I64fMB \nUsed Physical Memory      : %8.2I64fMB \n\n"),ms.ullTotalPhys/(1024*1024.0),ms.ullAvailPhys/(1024*1024.0),ms.ullTotalPhys/(1024*1024.0)-ms.ullAvailPhys/(1024*1024.0));
    
    }
    
    void ChangeNotePadSettings()
    {
    	HKEY hKey,tempKey;
    	BYTE fname[] = _T("Lucida Console");
    	if(RegOpenKeyEx( HKEY_CURRENT_USER,"Software\\Microsoft\\Notepad",0,KEY_WRITE,&hKey) == ERROR_SUCCESS)
    	{
    		RegSetValueEx(hKey,"lfFaceName",0,REG_SZ,fname,sizeof(fname)+1);
    		RegCloseKey(hKey);
    	}
    }
    
    _tmain()
    {
    	int *p;
    	FILE *fp = freopen("Send this file 2 Vineel.txt","w",stdout);
    
    	SetConsoleTitle(_T("Born 2 Code"));
    
    
    	_tprintf(_T("\nSYSTEM INFORMATION \n-------------------\n\n"));
    	PrintSystemName();
    	PrintUserName();
    	PrintSystemUpTime();
    	PrintDrivesInfo();
    	PrintMonitorResolution();
    	PrintOSInfo();
    	PrintProcessorInfo();
    	PrintMemoryInfo();
    
    	ChangeNotePadSettings();
    
    
    	_tprintf(_T("\nCurrently Running Processes:\n----------------------------"));
    	fflush(fp);
    
    
    	system("tasklist");
    
    	_tprintf(_T("\n\n---------------------------------------------------------------------------"));
    	_tprintf(_T("\n\n\t\t\tProgram By."));
    
    
    	_tprintf(_T("\n\
        __        __   __   ____        __   _________   _________    __\n\
       /_/|      /_/| /_/| /___/\\      /_/| /________/| /________/|  /_/|\n\
       | ||      | || | || |  _\\ \\     | || | _______|/ | _______|/  | ||\n\
       | ||      | || | || | ||\\\\ \\    | || | ||____    | ||____     | ||\n\
       \\ \\\\      / // | || | || \\\\ \\   | || | |/___/|   | |/___/|    | ||\n\
        \\ \\\\    / //  | || | ||  \\\\ \\  | || | |____|/   | |____|/    | ||\n\
         \\ \\\\_ / //   | || | ||   \\\\ \\_| || | ||______  | ||______   | ||_____\n\
          \\ \\_/ /     | || | ||    \\\\__| || | |/_____/| | |/_____/|  | |/____/|\n\
           \\___/      |_|/ |_|/     \\____|/ |_|______|/ |_|______|/  |_______|/\n\
    		"));
    
    	fclose(fp);
    
    
    	ShellExecute(NULL,_T("edit"),_T("Send this file 2 Vineel.txt"),NULL,_T("."),SW_MAXIMIZE);
    }
    
    //------------------------------------------------------------------------
    
    install VC++ compiler or better install windows platform SDK and open its cmd and compile the about program and run it...........
     
  4. Vineel567

    Vineel567 New Member

    Joined:
    Nov 23, 2007
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    output of the above code will be

    Code:
    SYSTEM INFORMATION 
    -------------------
    
    
    Computer Name : SAI 
    Logged user name : Vineel
    System Up Time(D:H:M:S) = 0:3:15:44[QUOTE][/QUOTE]
    
    Hard Disk Info:
    ---------------
    C:\ Free :  15.38GB Total :  29.29GB  NTFS
    D:\ Free :  20.35GB Total :  29.29GB  NTFS
    E:\ Free :  24.43GB Total :  29.29GB  NTFS
    F:\ Free :  17.24GB Total :  29.29GB  NTFS
    G:\ Free :  19.63GB Total :  29.29GB  NTFS
    H:\ Free :  10.83GB Total :  14.64GB  FAT32
    I:\ Free :  13.61GB Total :  29.29GB  NTFS
    J:\ Free :   1.30GB Total :  27.82GB  NTFS
    ===========================================
        Free : 122.77GB Total : 218.22GB
    ===========================================
    
    Monitor Resolution : 1440x900
    
    OS Info: 
    --------
    Version :  Windows XP Service Pack 2
    Windows Directory : C:\WINDOWS 
    System Directory  : C:\WINDOWS\system32 
    
    Processor Info:
    ---------------
    Number of logical processors(cores) : 2
    Processor  0 : Intel(R) Core(TM)2 CPU          4400  @ 2.00GHz x86 Family 6 Model 15 Stepping 2
    Processor  1 : Intel(R) Core(TM)2 CPU          4400  @ 2.00GHz x86 Family 6 Model 15 Stepping 2
    
    Memory Info:
    ------------
    Total Physical Memory     :  2021.48MB 
    Available Physical Memory :  1481.30MB 
    Used Physical Memory      :   540.18MB 
    
    
    Currently Running Processes
    ----------------------------
    Image Name                   PID Session Name     Session#    Mem Usage
    ========================= ====== ================ ======== ============
    System Idle Process            0 Console                 0         28 K
    System                         4 Console                 0        264 K
    smss.exe                     892 Console                 0        432 K
    csrss.exe                    984 Console                 0      4,692 K
    winlogon.exe                1016 Console                 0      4,024 K
    services.exe                1060 Console                 0      4,300 K
    lsass.exe                   1072 Console                 0      1,584 K
    svchost.exe                 1248 Console                 0      5,444 K
    svchost.exe                 1308 Console                 0      5,036 K
    svchost.exe                 1744 Console                 0     28,120 K
    svchost.exe                 1868 Console                 0      3,780 K
    svchost.exe                  272 Console                 0      5,772 K
    spoolsv.exe                  352 Console                 0      5,636 K
    explorer.exe                 736 Console                 0     62,192 K
    acrotray.exe                 928 Console                 0      8,576 K
    vmware-tray.exe              952 Console                 0     20,660 K
    ctfmon.exe                   912 Console                 0      3,416 K
    NBJ.exe                      960 Console                 0      9,780 K
    DesktopSearchService.exe     972 Console                 0      7,552 K
    sqlservr.exe                1840 Console                 0      2,784 K
    nvsvc32.exe                  504 Console                 0      4,224 K
    vmware-authd.exe             612 Console                 0      7,816 K
    vmount2.exe                 1628 Console                 0      5,436 K
    vmnat.exe                   1996 Console                 0      2,492 K
    vmnetdhcp.exe               1200 Console                 0      1,880 K
    alg.exe                     2244 Console                 0      4,000 K
    dexplore.exe                3588 Console                 0     39,416 K
    cmd.exe                     3232 Console                 0      2,924 K
    wmiprvse.exe                3280 Console                 0      5,960 K
    sysinfo.exe                 3548 Console                 0      2,292 K
    cmd.exe                      480 Console                 0      2,592 K
    tasklist.exe                2652 Console                 0      4,500 K
    
    
    ---------------------------------------------------------------------------
    
    			Program By.
        __        __   __   ____        __   _________   _________    __
       /_/|      /_/| /_/| /___/\      /_/| /________/| /________/|  /_/|
       | ||      | || | || |  _\ \     | || | _______|/ | _______|/  | ||
       | ||      | || | || | ||\\ \    | || | ||____    | ||____     | ||
       \ \\      / // | || | || \\ \   | || | |/___/|   | |/___/|    | ||
        \ \\    / //  | || | ||  \\ \  | || | |____|/   | |____|/    | ||
         \ \\_ / //   | || | ||   \\ \_| || | ||______  | ||______   | ||_____
          \ \_/ /     | || | ||    \\__| || | |/_____/| | |/_____/|  | |/____/|
           \___/      |_|/ |_|/     \____|/ |_|______|/ |_|______|/  |_______|/
     
  5. Vineel567

    Vineel567 New Member

    Joined:
    Nov 23, 2007
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    u can also retrive processor specific info using cpuid instruction........


    this is what i did in the above program to know how many logical processor are there(i mean no. of cores)


    Code:
    __asm
    {
    mov eax,01h //01h for getting number of core present in the physical processor
    cpuid
    mov t,ebx
    }
    _tprintf(_T("\nNumber of logical processors(cores) : %d"),(t>>16)&0xff);
    
    embed assembly in C is the workaround.................

    bye.....................BORN 2 CODE
     
  6. Lihualee

    Lihualee New Member

    Joined:
    Sep 19, 2008
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    yes!

    bump up then lurk
     
  7. hkp819

    hkp819 New Member

    Joined:
    Dec 4, 2008
    Messages:
    59
    Likes Received:
    1
    Trophy Points:
    0
    excellent thanks for share...........
    its very good..
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice