How can i get the Server configuration like System Name, SERVER Name, CPU, Physical memory, commit memory, last boot etc.,
Thanks in advance,
Prasad
How can i get the Server configuration like System Name, SERVER Name, CPU, Physical memory, commit memory, last boot etc.,
Thanks in advance,
Prasad
System.Environment
and System.Diagnostics.Process.GetCurrentProcess()
offer good starting points for some of this information (although the second is more about the current process, rather than system wide).
For things like memory counts and CPU usage you will likely want to use Peformance Counters.
The topic Using System Monitoring Components on MSDN offers a good intro into how to do this stuff.
For boot times you might find this other SO useful: Get the date-time of last windows shutdown event using .NET
If you want to get info from remote server you can use smth like this:
string query = "SELECT * FROM Win32_OperatingSystem";
ConnectionOptions connection = new ConnectionOptions();
if (machineName != "127.0.0.1") // if it is localhost an error'll occur
{
connection.Username = admLogon;
connection.Password = admPassword;
}
connection.EnablePrivileges = true;
connection.Impersonation = ImpersonationLevel.Impersonate;
ManagementScope managementScope = new ManagementScope(@"\\" + machineName + @"\root\CIMV2", connection);
managementScope.Connect();
ObjectQuery queryObj = new ObjectQuery(query);
ManagementObjectSearcher searcher = new ManagementObjectSearcher(managementScope, queryObj);
foreach (ManagementObject managementObj in searcher.Get())
{
string osName = managementObj.Properties["Caption"].Value.ToString();
string systemName = managementObj.Properties["csname"].Value;
string osVersion = managementObj.Properties["Version"].Value;
string manufacturer = managementObj.Properties["Manufacturer"].Value;
//etc
}