From 1b4a1dd52b048b380d6aa38e43d780eda7656889 Mon Sep 17 00:00:00 2001 From: efrick Date: Tue, 29 Jun 2021 11:17:15 -0400 Subject: [PATCH] Start of C# rewrite. #14 --- Sysinfo_Console/Sysinfo_Console.cs | 82 ++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 Sysinfo_Console/Sysinfo_Console.cs diff --git a/Sysinfo_Console/Sysinfo_Console.cs b/Sysinfo_Console/Sysinfo_Console.cs new file mode 100644 index 0000000..997888a --- /dev/null +++ b/Sysinfo_Console/Sysinfo_Console.cs @@ -0,0 +1,82 @@ +using System; +using System.Collections.Generic; +using System.Management; +using System.IO; +using System.Threading.Tasks; +using System.Text; +using System.Reflection; + +namespace Sysinfo_Console +{ + class Sysinfo_Console + { + public static List System_Information() + { + List all_info = new List(); + //Create an object of ManagementObjectSearcher class and pass query as parameter. + ManagementObjectSearcher win32_mos = new ManagementObjectSearcher("select * from Win32_OperatingSystem"); + ManagementObjectSearcher ram_mos = new ManagementObjectSearcher("select * from Win32_PhysicalMemory"); + + Double full_ram = 0; + + foreach (ManagementObject managementObject in win32_mos.Get()) + { + if (managementObject["Caption"] != null) + { + all_info.Add("Operating System Name: \n" + managementObject["Caption"].ToString()); + //Console.WriteLine("Operating System Name : " + managementObject["Caption"].ToString()); //Display operating system caption + } + if (managementObject["OSArchitecture"] != null) + { + all_info.Add("Operating System Architecture: \n" + managementObject["OSArchitecture"].ToString()); + //Console.WriteLine("Operating System Architecture : " + managementObject["OSArchitecture"].ToString()); //Display operating system architecture. + } + if (managementObject["CSDVersion"] != null) + { + all_info.Add(managementObject["CSDVersion"].ToString()); + //Console.WriteLine("Operating System Service Pack : " + managementObject["CSDVersion"].ToString()); //Display operating system version. + } + } + foreach(ManagementObject managementObject in ram_mos.Get()) + { + if (managementObject["Capacity"] != null) + { + //Console.WriteLine(managementObject["Capacity"].ToString()); + full_ram += Convert.ToDouble(managementObject["Capacity"].ToString()); + } + } + all_info.Add("RAM:\n" + (full_ram / 1073741824) + "GB"); + //Console.ReadKey(); + return all_info; + } + + public static void Display_System_Information(List computer_info) + { + Console.WriteLine("Displaying operating system info....\n"); + foreach (var p in computer_info) + { + Console.WriteLine(p); + } + } + + public static void Wirte_System_Information(List computer_info, String desktop_path) + { + String file_path = desktop_path + "\\Sysinfo.txt"; + File.WriteAllLines(file_path, computer_info); + Console.WriteLine("Writing info to: " + file_path); + //foreach (var line in computer_info) + //{ + // File.WriteAllLines(".\\Sysinfo.txt", line); + //} + } + static void Main(string[] args) + { + String current_path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); + String desktop_path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); + Console.WriteLine(current_path + "\n" + desktop_path); + List machine_info = System_Information(); + Display_System_Information(machine_info); + Wirte_System_Information(machine_info, desktop_path); + } + } +}