Click here to Skip to main content
16,007,472 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to get computer system hardware information(about battery,motherboard,cpu,keybooard) using a common c/c++ source code across different os like linux and windows? 


What I have tried:

i was thinking it to do with commands in windows and linux like( ls commands and wmic command ) and executing these commands through program

ex-
wmic baseboard
wmic cpu
lscpu

is there any other way
Posted
Updated 20-Jun-18 21:39pm
v2

1 solution

There is no generic OS independant method to retrieve such information because hardware related information is provided internally by device drivers (which are totally different on Windows and Linux) and made accessible with OS specific interfaces.

However, there are exceptions for hardware connected to a bus that can be accessed by a common library. An example is libusb (initially for Linux but also available for Windows) which can be used to enumerate USB devices and acccess them for basic information like VID, PID, manufacturer, and product name string.
 
Share this answer
 
Comments
Member 13863799 21-Jun-18 3:45am    
Hi Jochen ,
Thanks for the reply so how can we get those information for specific to linux?
Jochen Arndt 21-Jun-18 4:35am    
A lot of general system information can be found in the virtual /proc file system.
See https://www.tldp.org/LDP/Linux-Filesystem-Hierarchy/html/proc.html

Specific hardware information can be found in the /sys/class pseudo filesystem.
See http://man7.org/linux/man-pages/man5/sysfs.5.html

There you can get for example the battery status at /sys/class/power_supply/BAT<n>.

There are also often command line tools for specific hardware like upower for the battery status.

Another option is to parse the boot messages (using dmesg or if logged to file like /var/log/boot using that). It contains information about the detected hardware.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900