Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Management; //.NET
- using System.Diagnostics; //Mono
- class TestClass {
- public static bool IsRunningOnMono () {
- return Type.GetType ("Mono.Runtime") != null;
- }
- static int Main( string[] args ) {
- OperatingSystem os = System.Environment.OSVersion;
- Console.WriteLine("Machine: {0}", Environment.MachineName);
- Console.WriteLine("Platform: {0}", os.Platform);
- if (os.Platform == PlatformID.Unix) {
- Console.WriteLine("Total Memory: {0:N0} MB", CountPhysicalMemory());
- }
- else if (os.Platform == PlatformID.Win32NT) {
- Console.WriteLine("Total Memory: {0:N0} MB", CountPhysicalMemory());
- //this is completely redundant but keeping it anyway as
- //a reference for how PlatformID works.
- }
- else {
- Console.WriteLine("Platform: No idea what OS this is lol.");
- }
- Console.WriteLine("\nCLR Version: {0}", System.Environment.Version);
- Console.WriteLine("Thanks!");
- string o = Console.ReadLine();
- return 0;
- }
- private static UInt64 CountPhysicalMemory(){
- OperatingSystem os = System.Environment.OSVersion;
- if (!IsRunningOnMono()) {
- //.NET only
- ManagementObjectSearcher objects =
- new ManagementObjectSearcher(
- "SELECT * FROM Win32_PhysicalMemory");
- ManagementObjectCollection coll = objects.Get();
- UInt64 total = 0;
- foreach (ManagementObject obj in coll) {
- total += (UInt64)obj["Capacity"];
- }
- return total/1024/1024;
- }
- else {
- //Mono only
- var pc = new PerformanceCounter ("Mono Memory", "Total Physical Memory");
- return (UInt64)pc.RawValue/1024/1024;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement