C # Obtains the basic information of the system, mainly uses "systeminformation" and "Environment", here uses the WinForm demonstration,
Get some information about the system, in fact this can also be used by the console program. Here the demo is just a part of the output, and other interesting ones can be researched.
Add a RichTextBox to the form to output the information obtained.
The code is very simple, do not explain, directly attached
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.ComponentModel;4 usingSystem.Data;5 usingSystem.Drawing;6 usingSystem.Linq;7 usingSystem.Text;8 usingSystem.Threading.Tasks;9 usingSystem.Windows.Forms;Ten One namespaceWinfrmtester A { - Public Partial classForm1:form - { the PublicForm1 () - { - InitializeComponent (); - } + - Private voidForm1_Load (Objectsender, EventArgs e) + { ARichtextbox1.appendtext ("Computer Name:"+systeminformation.computername); atRichtextbox1.appendtext (Environment.NewLine);//line Break -Richtextbox1.appendtext ("Computer Name:"+environment.machinename); - Richtextbox1.appendtext (Environment.NewLine); -Richtextbox1.appendtext ("Operating System:"+Environment.OSVersion.Platform); - Richtextbox1.appendtext (Environment.NewLine); -Richtextbox1.appendtext ("Version number:"+Environment.OSVersion.VersionString); in Richtextbox1.appendtext (Environment.NewLine); -Richtextbox1.appendtext ("number of processors:"+environment.processorcount); to Richtextbox1.appendtext (Environment.NewLine); + //determine the number of operating system bits - if(Environment.is64bitoperatingsystem) the { *Richtextbox1.appendtext ("number of operating system bits: 64bit."); $ }Panax Notoginseng Else - { theRichtextbox1.appendtext ("number of operating system bits: 32bit."); + } A Richtextbox1.appendtext (Environment.NewLine); the //determine if the network is connected + if(systeminformation.network) - { $Richtextbox1.appendtext ("Network connection: Connected"); $ } - Else - { theRichtextbox1.appendtext ("Network connection: not connected"); - }Wuyi Richtextbox1.appendtext (Environment.NewLine); the //judging the startup mode - if(SystemInformation.BootMode.ToString () = ="Normal") WuRichtextbox1.appendtext ("startup mode: normal start"); - if(SystemInformation.BootMode.ToString () = ="FailSafe") AboutRichtextbox1.appendtext ("startup mode: Secure Boot"); $ if(SystemInformation.BootMode.ToString () = ="failsafewithnework") -Richtextbox1.appendtext ("start mode: Start with network service"); - Richtextbox1.appendtext (Environment.NewLine); -Richtextbox1.appendtext ("number of monitors:"+systeminformation.monitorcount); A Richtextbox1.appendtext (Environment.NewLine); +Richtextbox1.appendtext ("Display resolution:"+ SystemInformation.PrimaryMonitorMaximizedWindowSize.Width +"x"+SystemInformation.PrimaryMonitorMaximizedWindowSize.Height); the Richtextbox1.appendtext (Environment.NewLine); -Richtextbox1.appendtext ("main Display current resolution:"+systeminformation.primarymonitorsize.width +"x"+SystemInformation.PrimaryMonitorSize.Height); $ Richtextbox1.appendtext (Environment.NewLine); theRichtextbox1.appendtext ("Number of mouse buttons:"+systeminformation.mousebuttons.tostring ());//I don't know how to get it, it's a 5 button . the Richtextbox1.appendtext (Environment.NewLine); theRichtextbox1.appendtext ("System-Qualified directory:"+environment.systemdirectory); the Richtextbox1.appendtext (Environment.NewLine); -Richtextbox1.appendtext ("system Memory:"+Environment.SystemPageSize.ToString ()); in Richtextbox1.appendtext (Environment.NewLine); the } the } About}
The effect of the final output
[C # learning Note 1] getting the current system basic information