C method to get system version information

  • 2020-05-07 20:21:04
  • OfStack

Direct paste code:
 
public class OSInfoMation 
{ 
public static string OSBit() 
{ 
try 
{ 
ConnectionOptions oConn = new ConnectionOptions(); 
System.Management.ManagementScope managementScope = new System.Management.ManagementScope("\\\\localhost", oConn); 
System.Management.ObjectQuery objectQuery = new System.Management.ObjectQuery("select AddressWidth from Win32_Processor"); 
ManagementObjectSearcher moSearcher = new ManagementObjectSearcher(managementScope, objectQuery); 
ManagementObjectCollection moReturnCollection = null; 
string addressWidth = null; 
moReturnCollection = moSearcher.Get(); 
foreach (ManagementObject oReturn in moReturnCollection) 
{ 
addressWidth = oReturn["AddressWidth"].ToString(); 
} //www.heatpress123.net 
return addressWidth; 
} 
catch 
{ 
return " Get error "; 
} 
} 
public static string GetOsVersion() 
{ 
string osBitString = OSBit(); 
string osVersionString = Environment.OSVersion.ToString(); 
return string.Format(@" System: {0} . A: {1}", osVersionString, osBitString); 
} 
} 

Call:
 
static void Main(string[] args) 
{ 
Console.WriteLine(OSInfoMation.GetOsVersion()); 
Console.ReadLine(); 
} 

Related articles: