System Information


Get your Syserm information using following code

Hi All

I saw lot of forum questions about system information. But they have very few answers.
I found one name space System.Management; By using that we can get lot of information. We can get it from Win32 directly.
It can be used to enumerate all disk drives, network adapters, processes and many more management objects on a system, or to query for all network connections that are up, services that are paused, and so on.
This should be very usfull for all.
Following are some examples to get the system information


using System;
using System.Management;


Win32_OperatingSystem

ManagementObjectSearcher MyQManagementObjectSearcher = new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem") ;
ManagementObjectCollection MyMOCollection = MyQManagementObjectSearcher.Get();

foreach( ManagementObject MyMO in MyMOCollection )
{
Console.WriteLine(MyMO["name"].ToString());
Console.WriteLine(MyMO["version"].ToString());
Console.WriteLine(MyMO["Manufacturer"].ToString());
Console.WriteLine(MyMO["csname"].ToString());
Console.WriteLine(MyMO["WindowsDirectory"].ToString());
}

Win32_ComputerSystem

MyQManagementObjectSearcher = new ManagementObjectSearcher("SELECT * FROM Win32_ComputerSystem") ;
MyMOCollection = MyQManagementObjectSearcher.Get();

foreach( ManagementObject MyMO in MyMOCollection )
{
Console.WriteLine(MyMO["manufacturer"].ToString());
Console.WriteLine(MyMO["model"].ToString());
Console.WriteLine(MyMO["systemtype"].ToString());
Console.WriteLine(MyMO["totalphysicalmemory"].ToString());
}

Win32_NetworkAdapterConfiguration

MyQManagementObjectSearcher = ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'TRUE'") ;
MyMOCollection = MyQManagementObjectSearcher.Get();
foreach( ManagementObject MyMO in MyMOCollection)
{
string[] MyIPAddress = (string[])MyMO["IPAddress"];
string[] MyIPSubnet = (string[])MyMO["IPSubnet"];
string[] MyDefaultIPGateway = (string[])MyMO["DefaultIPGateway"];

Console.WriteLine("Network Card: {0}", MyMO["Description"]);
Console.WriteLine(" MAC Address: {0}", MyMO["MACAddress"]);

foreach(string ipaddress in MyIPAddress)
{
Console.WriteLine( ipaddress);
}
foreach(string subnet in MyIPSubnet)
{
Console.WriteLine(subnet);
}
foreach(string defaultgateway in MyDefaultIPGateway)
{
Console.WriteLine(defaultgateway);
}
}

Win32_processor

MyQManagementObjectSearcher = new ManagementObjectSearcher("SELECT * FROM Win32_processor") ;
MyMOCollection = MyQManagementObjectSearcher.Get();
foreach( ManagementObject MyMO in MyMOCollection )
{
Console.WriteLine(MyMO["caption"].ToString());
}


Win32_bios

MyQManagementObjectSearcher = new ManagementObjectSearcher("SELECT * FROM Win32_bios") ;
MyMOCollection = MyQManagementObjectSearcher.Get();
foreach(ManagementObject MyMO in MyMOCollection )
{
Console.WriteLine(MyMO["version"].ToString());
}


Win32_timezone
MyQManagementObjectSearcher = new ManagementObjectSearcher("SELECT * FROM Win32_timezone") ;

MyMOCollection = MyQManagementObjectSearcher.Get();
foreach( ManagementObject MyMO in MyMOCollection)
{
Console.WriteLine(MyMO["caption"].ToString());
}

For more reference : http://msdn.microsoft.com/en-us/library/system.management(v=VS.100).aspx

By
Nathan


Comments

Author: Jai27 Apr 2010 Member Level: Gold   Points : 0

Nice..
its very useful

Author: asdfg27 Apr 2010 Member Level: Gold   Points : 0

Thank you for sharing with us

Author: Nathan29 Apr 2010 Member Level: Gold   Points : 0

Thanks for you response

Author: Nishikant03 May 2010 Member Level: Gold   Points : 1

Hi,

Thanks for sharing the information.

It was very helpful.

Regards,

Nishikant K

Author: Arijit Das05 Oct 2010 Member Level: Gold   Points : 1

The "System.Management" namespace is not at all available while coding with Visual Basic(VB.Net) for WindowsApplication. I got this issue when I was trying to apply these code using Visual Studio 2005.

Any better idea for resolving this issue?

Author: Nathan06 Oct 2010 Member Level: Gold   Points : 1

'To use this class you must add a reference
'to System.Management from the Project | References
'menu

Imports System.Management



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: