Jump to content

C# - How can I access this data correctly?

AlTech

So I want to access some data correctly but despite my numerous attempts I have not been able to get this to work properly.

 

1. I'm trying to find the correct total amount of RAM installed and available RAM.

 

I tried using the Microsoft.VisualBasic Library and added it as a reference.

 

And it's showing more RAM than I have. So how can I get RAM information correctly?

 

			ulong physicalmemory = new ComputerInfo().TotalPhysicalMemory / 1000000000;
            int convertedphysical = Convert.ToInt32(physicalmemory);
            total_ram.Text = convertedphysical.ToString() + "GB";

            ulong available = new ComputerInfo().AvailablePhysicalMemory / 1000000000;
            int convertedavailable = Convert.ToInt32(available);
            available_ram.Text = convertedavailable.ToString() + "GB";

 

 

2. How can I find out what exact  OS Build someone has? I tried using what version of IE installed was to guess but I found this to be not accurate for anybody on Windows 8, 8.1 or Windows 7.

Judge a product on its own merits AND the company that made it.

How to setup MSI Afterburner OSD | How to make your AMD Radeon GPU more efficient with Radeon Chill | (Probably) Why LMG Merch shipping to the EU is expensive

Oneplus 6 (Early 2023 to present) | HP Envy 15" x360 R7 5700U (Mid 2021 to present) | Steam Deck (Late 2022 to present)

 

Mid 2023 AlTech Desktop Refresh - AMD R7 5800X (Mid 2023), XFX Radeon RX 6700XT MBA (Mid 2021), MSI X370 Gaming Pro Carbon (Early 2018), 32GB DDR4-3200 (16GB x2) (Mid 2022

Noctua NH-D15 (Early 2021), Corsair MP510 1.92TB NVMe SSD (Mid 2020), beQuiet Pure Wings 2 140mm x2 & 120mm x1 (Mid 2023),

Link to comment
Share on other sites

Link to post
Share on other sites

@patrickjp93
u the coding guy right?
help this person out :P

hello!

is it me you're looking for?

ᴾC SᴾeCS ᴰoWᴺ ᴮEᴸoW

Spoiler

Desktop: X99-PC

CPU: i7 5820k

Mobo: X99 Deluxe

Cooler: Dark Rock Pro 3

RAM: 32GB DDR4
GPU: GTX 1080

Storage: 1TB 850 Evo, 1TB HDD, bunch of external hard drives
PSU: EVGA G2 750w

Peripherals: Logitech G502, Ducky One 711

Audio: Xonar U7, O2 amplifier (RIP), HD6XX

Monitors: 4k 24" Dell monitor, 1080p 24" Asus monitor

 

Laptop:

-Overkill Dell XPS

Fully maxed out early 2017 Dell XPS 15, GTX 1050 4GB, 7700HQ, 1TB nvme SSD, 32GB RAM, 4k display. 97Whr battery :x 
Dell was having a $600 off sale for the fully specced out model, so I decided to get it :P

 

-Crapbook

Fully specced out early 2013 Macbook "pro" with gt 650m and constant 105c temperature on the CPU (GPU is 80-90C) when doing anything intensive...

A 2013 laptop with a regular sized battery still has better battery life than a 2017 laptop with a massive battery! I think this is a testament to apple's ability at making laptops, or maybe how little CPU technology has improved even 4+ years later (at least, until the recent introduction of 15W 4 core CPUs). Anyway, I'm never going to get a 35W CPU laptop again unless battery technology becomes ~5x better than as it is in 2018.

Apple knows how to make proper consumer-grade laptops (they don't know how to make pro laptops though). I guess this mostly software power efficiency related, but getting a mac makes perfect sense if you want a portable/powerful laptop that can do anything you want it to with great battery life.

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

I might have found a solution for the total RAM but not for available RAM.


EDIT: ooops nvm :(.

 

 

Judge a product on its own merits AND the company that made it.

How to setup MSI Afterburner OSD | How to make your AMD Radeon GPU more efficient with Radeon Chill | (Probably) Why LMG Merch shipping to the EU is expensive

Oneplus 6 (Early 2023 to present) | HP Envy 15" x360 R7 5700U (Mid 2021 to present) | Steam Deck (Late 2022 to present)

 

Mid 2023 AlTech Desktop Refresh - AMD R7 5800X (Mid 2023), XFX Radeon RX 6700XT MBA (Mid 2021), MSI X370 Gaming Pro Carbon (Early 2018), 32GB DDR4-3200 (16GB x2) (Mid 2022

Noctua NH-D15 (Early 2021), Corsair MP510 1.92TB NVMe SSD (Mid 2020), beQuiet Pure Wings 2 140mm x2 & 120mm x1 (Mid 2023),

Link to comment
Share on other sites

Link to post
Share on other sites

6 minutes ago, rattacko123 said:

@patrickjp93
u the coding guy right?
help this person out :P

There's no one "Coding Guy". A few people on the forum do programming.

Judge a product on its own merits AND the company that made it.

How to setup MSI Afterburner OSD | How to make your AMD Radeon GPU more efficient with Radeon Chill | (Probably) Why LMG Merch shipping to the EU is expensive

Oneplus 6 (Early 2023 to present) | HP Envy 15" x360 R7 5700U (Mid 2021 to present) | Steam Deck (Late 2022 to present)

 

Mid 2023 AlTech Desktop Refresh - AMD R7 5800X (Mid 2023), XFX Radeon RX 6700XT MBA (Mid 2021), MSI X370 Gaming Pro Carbon (Early 2018), 32GB DDR4-3200 (16GB x2) (Mid 2022

Noctua NH-D15 (Early 2021), Corsair MP510 1.92TB NVMe SSD (Mid 2020), beQuiet Pure Wings 2 140mm x2 & 120mm x1 (Mid 2023),

Link to comment
Share on other sites

Link to post
Share on other sites

Fixed the memory part. I needed to divide by 1.024 billion :) instead of 1 billion.

Judge a product on its own merits AND the company that made it.

How to setup MSI Afterburner OSD | How to make your AMD Radeon GPU more efficient with Radeon Chill | (Probably) Why LMG Merch shipping to the EU is expensive

Oneplus 6 (Early 2023 to present) | HP Envy 15" x360 R7 5700U (Mid 2021 to present) | Steam Deck (Late 2022 to present)

 

Mid 2023 AlTech Desktop Refresh - AMD R7 5800X (Mid 2023), XFX Radeon RX 6700XT MBA (Mid 2021), MSI X370 Gaming Pro Carbon (Early 2018), 32GB DDR4-3200 (16GB x2) (Mid 2022

Noctua NH-D15 (Early 2021), Corsair MP510 1.92TB NVMe SSD (Mid 2020), beQuiet Pure Wings 2 140mm x2 & 120mm x1 (Mid 2023),

Link to comment
Share on other sites

Link to post
Share on other sites

seeing as a byte is 1024 bits ;)

3 hours ago, AluminiumTech said:

Fixed the memory part. I needed to divide by 1.024 billion :) instead of 1 billion.

 

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, vorticalbox said:

seeing as a byte is 1024 bits ;)

 

I'm hearing of strange issue where a PC with 24GB will show 25GB using the calculation......

Any idea on what might cause that?

Judge a product on its own merits AND the company that made it.

How to setup MSI Afterburner OSD | How to make your AMD Radeon GPU more efficient with Radeon Chill | (Probably) Why LMG Merch shipping to the EU is expensive

Oneplus 6 (Early 2023 to present) | HP Envy 15" x360 R7 5700U (Mid 2021 to present) | Steam Deck (Late 2022 to present)

 

Mid 2023 AlTech Desktop Refresh - AMD R7 5800X (Mid 2023), XFX Radeon RX 6700XT MBA (Mid 2021), MSI X370 Gaming Pro Carbon (Early 2018), 32GB DDR4-3200 (16GB x2) (Mid 2022

Noctua NH-D15 (Early 2021), Corsair MP510 1.92TB NVMe SSD (Mid 2020), beQuiet Pure Wings 2 140mm x2 & 120mm x1 (Mid 2023),

Link to comment
Share on other sites

Link to post
Share on other sites

9 minutes ago, vorticalbox said:

seeing as a byte is 1024 bits ;)

 

Also, do you know of any way where I can determine what OS build they are running?

 

E.g. Windows 10 Build 10.0.10240 or 10.0.14393 etc

Judge a product on its own merits AND the company that made it.

How to setup MSI Afterburner OSD | How to make your AMD Radeon GPU more efficient with Radeon Chill | (Probably) Why LMG Merch shipping to the EU is expensive

Oneplus 6 (Early 2023 to present) | HP Envy 15" x360 R7 5700U (Mid 2021 to present) | Steam Deck (Late 2022 to present)

 

Mid 2023 AlTech Desktop Refresh - AMD R7 5800X (Mid 2023), XFX Radeon RX 6700XT MBA (Mid 2021), MSI X370 Gaming Pro Carbon (Early 2018), 32GB DDR4-3200 (16GB x2) (Mid 2022

Noctua NH-D15 (Early 2021), Corsair MP510 1.92TB NVMe SSD (Mid 2020), beQuiet Pure Wings 2 140mm x2 & 120mm x1 (Mid 2023),

Link to comment
Share on other sites

Link to post
Share on other sites

30 minutes ago, AluminiumTech said:

I'm hearing of strange issue where a PC with 24GB will show 25GB using the calculation......

Any idea on what might cause that?

A Kibibyte = 1024 bytes

A Mebibyte = 1024 Kibibytes

A GibiByte = 1024 Mebibytes

 

So you need to divide by (1024 * 1024 * 1024).

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, Unimportant said:

A Kibibyte = 1024 bytes

A Mebibyte = 1024 Kibibytes

A GibiByte = 1024 Mebibytes

 

So you need to divide by (1024 * 1024 * 1024).

Oh. Ok. So I need to do per  stage and I can't do it in one go?


Gotcha! Any ideas for Windows build?

Judge a product on its own merits AND the company that made it.

How to setup MSI Afterburner OSD | How to make your AMD Radeon GPU more efficient with Radeon Chill | (Probably) Why LMG Merch shipping to the EU is expensive

Oneplus 6 (Early 2023 to present) | HP Envy 15" x360 R7 5700U (Mid 2021 to present) | Steam Deck (Late 2022 to present)

 

Mid 2023 AlTech Desktop Refresh - AMD R7 5800X (Mid 2023), XFX Radeon RX 6700XT MBA (Mid 2021), MSI X370 Gaming Pro Carbon (Early 2018), 32GB DDR4-3200 (16GB x2) (Mid 2022

Noctua NH-D15 (Early 2021), Corsair MP510 1.92TB NVMe SSD (Mid 2020), beQuiet Pure Wings 2 140mm x2 & 120mm x1 (Mid 2023),

Link to comment
Share on other sites

Link to post
Share on other sites

As per which OS, you have to query for the kernel and use a lookup table.

 

As for RAM, I believe the technique you're currently using is giving you all virtual memory too.

 

I haven't needed to use these particular aspects of C# before. The deepest I ever went into that rabbit hole was using Reflection.

Software Engineer for Suncorp (Australia), Computer Tech Enthusiast, Miami University Graduate, Nerd

Link to comment
Share on other sites

Link to post
Share on other sites

Windows version :  https://github.com/lordmulder/stdutils/blob/1.09/Contrib/StdUtils/src/DetectOsVersion.cpp

 

See thread here : http://forum.doom9.org/showthread.php?p=1767546  -  I copied the above link from there, and it contains more explanations about why getting accurate windows versions may be more difficult as time goes by

 

As for hardware information, the most elegant way would be to use WMI (Windows Management Instrumentation) , there are built in WMI Classes for that,so you can just parse all the information and build up information about how much memory the system has available : https://msdn.microsoft.com/en-us/library/aa389273(v=vs.85).aspx#_hmm_motherboard_controller_and_port_classes

 

Link to comment
Share on other sites

Link to post
Share on other sites

9 hours ago, mariushm said:

Windows version :  https://github.com/lordmulder/stdutils/blob/1.09/Contrib/StdUtils/src/DetectOsVersion.cpp

 

See thread here : http://forum.doom9.org/showthread.php?p=1767546  -  I copied the above link from there, and it contains more explanations about why getting accurate windows versions may be more difficult as time goes by

 

As for hardware information, the most elegant way would be to use WMI (Windows Management Instrumentation) , there are built in WMI Classes for that,so you can just parse all the information and build up information about how much memory the system has available : https://msdn.microsoft.com/en-us/library/aa389273(v=vs.85).aspx#_hmm_motherboard_controller_and_port_classes

 

But that Windows version thing is in C++. I'm not using C++. I now I could get the build number from the registry but I don't think that's a good idea.

Judge a product on its own merits AND the company that made it.

How to setup MSI Afterburner OSD | How to make your AMD Radeon GPU more efficient with Radeon Chill | (Probably) Why LMG Merch shipping to the EU is expensive

Oneplus 6 (Early 2023 to present) | HP Envy 15" x360 R7 5700U (Mid 2021 to present) | Steam Deck (Late 2022 to present)

 

Mid 2023 AlTech Desktop Refresh - AMD R7 5800X (Mid 2023), XFX Radeon RX 6700XT MBA (Mid 2021), MSI X370 Gaming Pro Carbon (Early 2018), 32GB DDR4-3200 (16GB x2) (Mid 2022

Noctua NH-D15 (Early 2021), Corsair MP510 1.92TB NVMe SSD (Mid 2020), beQuiet Pure Wings 2 140mm x2 & 120mm x1 (Mid 2023),

Link to comment
Share on other sites

Link to post
Share on other sites

You can call Windows API functions from your preferred language, they're not something specific to C++. 

The IF in C++ is also an IF in C# or Visual Basic .net or whatever you use, the FOR and WHILE are the same in lots of languages, you can TRANSLATE the C++ code to your programming language. Just be patient and try to UNDERSTAND what happens in the C++ code and you'll be able to adapt it to your program.

 

See https://msdn.microsoft.com/en-us/library/172wfck9.aspx (for vb.net) or http://www.codeproject.com/Articles/1285/Calling-API-functions-using-C for c# or  https://visualstudiomagazine.com/articles/2010/04/20/call-win32-api-functions-in-vb.aspx which even contains an example in vb .net (very easy to convert to c#) of using API functions to determine windows version (but slightly inaccurate/incomplete these days as doesn't cover all cases)

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×