Get system information in DOTNET (1)

xiaoxiao2021-03-06  40

A few days a few days, I sent an essay with C # to obtain system information, got a lot of high people's guidance, good luck!

These two days have evacuated it, use the Singleton mode, and support information for reading multi-CPU and multi-NIC (not using WMI), but there is no way to test, don't know! Please guide your guidance!

TestDriver.net (previously called NUNITDIN) and RESHARPER 1.0 are used in the whole process, it is true. Especially the resharper, the reconstruction function is much better than TOGETHER for VS.NET 2.0, and other functions are also good (so VAX and CODERUSH are abandoned, and more resources are too resource).

There are more code, first hair: systemInfomation.cs

Using

System;

Using

System.net;

Using

Microsoft.win32;

Namespace

SystemInfomation

{Public struct RunnedTime {public int hour; public int minute; public int second;} / ** ////

/// Summary description for GetInfo /// public class SystemInfomation {private static SystemInfomation. instance; private const string processorKey = @ "HARDWARE / DESCRIPTION / System / CentralProcessor /"; private const string biosKey = @ "HARDWARE / DESCRIPTION / System"; private const string networkKey = @ "SOFTWARE / Microsoft / Windows NT / CurrentVersion / NetworkCards / "; // private static registryKey Bios; // private static registryKey network; ////// /// Get Subkeys of processor registry. /// /// Subkeys: Stirng [] private string [] getProcessorKey () {Try {registryKey processor = registry.localmachine.OpensubKey (ProcessorKey); Return Processor.getsubKeynames (); Catch (Exception E) {throw (e);}} / ** //// /// Get Bios Registry. /// /// Registry private static registryKey getBioskey () {return registry.localmachine.opensubKey (Bioskey);} / ** //// /// Get Subkeys of Netword card registry. /// /// Subkeys: String []

private string [] GetNetworkKey () {try {RegistryKey network = Registry.LocalMachine.OpenSubKey (networkKey); return network.GetSubKeyNames ();} catch (Exception e) {throw (e);}} public SystemInfomation () {// // Todo: add constructor logic here //} / ** ////

/// Singleton model /// /// instance: systemInfo public systeminfomation getInstance ) {Loc (instance == null) {instance = new systemInfomation ();}} returnfomation;} / ** //// /// Get OS Version. /// /// OS_VERSION: STRING public string getosversion () { Return system.environment.osversion.tostring ();} / ** //// /// Get machine name /// /// machine_name: string public string GetMachinename () {return system.environment.machinename.toString ();} / ** //// /// Get user name of using os /// /// user_name: String public string getUsername () {return system.environment.Username.tostring ();} / ** ////

/// Get All logic drivers of machine /// /// logic_drivers: string [] public string [] getLogicalDrives () {returncture system.environment.getLogicalDrives ();} / ** ////

/// Get IP Address of Machine /// /// ip_addr: ipaddress [] public ipaddress [iphostentry ipAddr () {iphostentry ipentry = DNS.GETHOSTBYNAME (DNS.GETHOSTNAME ()); return penntry.addresslist;} / ** //// /// Get Domain Name /// /// domain_name: stirng < / returns> public string getDomainName () {return system.environment.userdomainname.tostring ();} / ** //// /// Get Boot Mode of OS /// /// < Returns> Boot_Mode: Stirng public string getbootmode () {return system.windows.Forms.systeminformation.boo TMODE.TOSTRING ();} / ** //// /// GET Used Memory of OS /// /// USED_MEMORY: STRING public string getusedMemory () {RETURN (System.Environment.WorkingSet / (1024.0 * 1024.0)). TOSTRING ("f") "m";} / ** //// /// get system directory /// /// sys_dir: string public string getsystem.Tostring ();} / ** ////

/// Get Temp Directory //// /// TMP_DIR: STRING public string getTempdirectory () {Return System.environment.GetenvironmentVariable ("temp"). Tostring ();} / ** ////

/// Get Dotnet framework version /// /// fxversion: String public string getfxversion () {return system.environment.Version.toString () / ** //// /// Get Runned Time of OS /// /// RunnedTime Struct Public RunnedTime GetosrunnedTime () {INT T System.environment.tickcount / 1000; int _ hour = t / 3600; int _Minute = T / 60 - _Hour * 60; int _Second = T - _Hour * 3600 - _Minute * 60; runnedtime time; time.hour = _HOUR; time. Minute = _minute; time.second = _second; returnit;} / ** //// /// get processor's names /// /// processor_names: string [] public string [] getProcessorname () {string [] Processornames ; RegistryKey key = null; try {string [] subKeys = GetProcessorKey (); processorNames = new string [subKeys.Length]; for (int i = 0; i

Processornames [i] = key.getValue ("processornameString"). TOSTRING ();}} Catch (Exception E) {throw (e);} finally {i (key! = null) {key.close ();} Return Processornames;} / ** ////

/// get processor Identifier /// /// processor_id: string [] public string [] getProcessorIdentifier () { string [] processorId; RegistryKey key = null; try {string [] subKeys = GetProcessorKey (); processorId = new string [subKeys.Length]; for (int i = 0; i /// Get Vendor Identifier /// /// vendor_id: string [] public string [] getvendorIndifier () {Try {string [] Subkeys = getProcessorKey (); string [] vendorid = NULL;

RegistryKey Key; for (int i = 0; i /// get processor frequency (mhz) /// /// processor_freq: string [] public string [] GetProcessorFrequency () {string [] processorFrequency; RegistryKey key = null; try {string [] subKeys = GetProcessorKey (); processorFrequency = new string [subKeys.Length] For (int i = 0; i /// Get Bios Identifier /// /// BIOS_ID: String

Public string getbiosidentifier () {return getbioskey (). getValue ("Identifier"). Tostring ();} / ** ////

/// Get Bios Version /// /// < Returns> BIOS_VERSION: STRING [] public string [] getSystemBiosversion () {return (String []) getbioskey (). getValue ("systembiosversion");} / ** //// /// Get video biso version /// /// video_biso_version: string public string [] getVideoBiosVersion () {return (String []) getbioskey (). GetValue ("VideoBiosVersion");} / ** //// /// get video bios Date /// /// video_biso_date: string [] public string getvideobiosdate () {return getbioskey (). GetValue ("VideoBiosDate"). Tostring ();} / ** //// /// Get Network cards description infomation /// /// network_card_info: string [] public string [] GetNetworkCardsInfo () {string [] networkInfo; RegistryKey key = null; try {string [] subKeys = GetNetworkKey (); networkInfo = NEW STRING [Subkeys.Length]; for (int i = 0; i
转载请注明原文地址:https://www.9cbs.com/read-57097.html

New Post(0)