How to get server config in C #
2 answers
If you want to get information from a 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
}
+3
source to share
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, not system-wide).
For things like memory counts and CPU usage, you most likely want to use form counters.
The topic Using System Monitoring Components on MSDN offers a good idea of how to do this.
For boot times, you may find this other SO helpful: Get Windows Last Shutdown Date-Time Using .NET
+4
source to share