I want to check what type of operating system i use and what kind of processor. this should be check on run time. i tried using
System.Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE")
and
System.OperatingSystem osInfo2 = System.Environment.OSVersion;
Console.WriteLine(osInfo2.ToString());
but it's just the enviroment that VS is running on.
I was told to use WMI to check it but i can't find out how.
can someone help me with that?
Android DevicesGo to the home screen of your device. Touch "Settings," then touch "About Phone" or "About Device." From there, you can find the Android version of your device.
C was invented to write an operating system called UNIX. C is a successor of B language which was introduced around the early 1970s. The language was formalized in 1988 by the American National Standard Institute (ANSI). The UNIX OS was totally written in C.
Click Start, type system in the search box, and then click System in the Control Panel list. The operating system is displayed as follows: For a 64-bit version operating system: 64-bit Operating System appears for the System type under System.
Software Engineering C To check the operating system of the host in a C or C++ code, we need to check the macros defined by the compiler (GNU GCC or G++). For example, on Windows platform, the compiler has a special macro named _WIN32 defined. So, if the macro _WIN32 is defined, we are on Windows.
Retrieving OS info:
var wmi =
new ManagementObjectSearcher( "select * from Win32_OperatingSystem" )
.Get()
.Cast<ManagementObject>()
.First();
OS.Name = ((string)wmi["Caption"]).Trim();
OS.Version = (string)wmi["Version"];
OS.MaxProcessCount = (uint)wmi["MaxNumberOfProcesses"];
OS.MaxProcessRAM = (ulong)wmi["MaxProcessMemorySize"];
OS.Architecture = (string)wmi["OSArchitecture"];
OS.SerialNumber = (string)wmi["SerialNumber"];
OS.Build = ((string)wmi["BuildNumber"]).ToUint();
Retrieving CPU info:
var cpu =
new ManagementObjectSearcher( "select * from Win32_Processor" )
.Get()
.Cast<ManagementObject>()
.First();
CPU.ID = (string)cpu["ProcessorId"];
CPU.Socket = (string)cpu["SocketDesignation"];
CPU.Name = (string)cpu["Name"];
CPU.Description = (string)cpu["Caption"];
CPU.AddressWidth = (ushort)cpu["AddressWidth"];
CPU.DataWidth = (ushort)cpu["DataWidth"];
CPU.Architecture = (CPU.CpuArchitecture)(ushort)cpu["Architecture"];
CPU.SpeedMHz = (uint)cpu["MaxClockSpeed"];
CPU.BusSpeedMHz = (uint)cpu["ExtClock"];
CPU.L2Cache = (uint)cpu["L2CacheSize"] * (ulong)1024;
CPU.L3Cache = (uint)cpu["L3CacheSize"] * (ulong)1024;
CPU.Cores = (uint)cpu["NumberOfCores"];
CPU.Threads = (uint)cpu["NumberOfLogicalProcessors"];
CPU.Name =
CPU.Name
.Replace( "(TM)", "™" )
.Replace( "(tm)", "™" )
.Replace( "(R)", "®" )
.Replace( "(r)", "®" )
.Replace( "(C)", "©" )
.Replace( "(c)", "©" )
.Replace( " ", " " )
.Replace( " ", " " );
Yes WMI is the best way to do this kind of stuff You can use this to retrieve OS informations :
ManagementObjectSearcher objMOS = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_OperatingSystem");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With