using System.Management;
using System.Diagnostics;
class MachineInfo
{
ManagementObjectSearcher query;
ManagementObjectCollection result;
string responseString;
int responseInt;
public string GetMachineName()
{
return Environment.MachineName.ToUpper();
}
public string GetOSVersion()
{
return Environment.OSVersion.VersionString;
}
public string GetProcessorCount()
{
return Environment.ProcessorCount.ToString();
}
public string GetIPAddress()
{
IPHostEntry ipEntry = Dns.GetHostEntry(Dns.GetHostName());
IPAddress[] ipAddress = ipEntry.AddressList;
return ipAddress[0].ToString();
}
public string GetTotalPhysicalMemory()
{
query = new ManagementObjectSearcher("SELECT * FROM Win32_LogicalMemoryConfiguration");
result = query.Get();
foreach (ManagementObject managementObject in result)
{
responseInt = Convert.ToInt32(managementObject["TotalPhysicalMemory"].ToString());
}
responseInt = (responseInt / 1024);
responseString = responseInt.ToString() + " MB";
return responseString;
}
public string GetAvailablePhysicalMemory()
{
PerformanceCounter counter = new PerformanceCounter("Memory", "Available Bytes");
responseInt = ((int)Convert.ToInt64(counter.NextValue())) / (1024 * 1024);
responseString = responseInt.ToString() + " MB";
return responseString;
}
public string GetTotalVirtualMemory()
{
query = new ManagementObjectSearcher("SELECT * FROM Win32_LogicalMemoryConfiguration");
result = query.Get();
foreach (ManagementObject managementObject in result)
{
responseInt = Convert.ToInt32(managementObject["TotalVirtualMemory"].ToString());
}
responseInt = (responseInt / 1024);
responseString = responseInt.ToString() + " MB";
return responseString;
}
public string GetAvailableVirtualMemory()
{
query = new ManagementObjectSearcher("SELECT * FROM Win32_LogicalMemoryConfiguration");
result = query.Get();
foreach (ManagementObject managementObject in result)
{
responseInt = Convert.ToInt32(managementObject["AvailableVirtualMemory"].ToString());
}
responseInt = (responseInt / 1024);
responseString = responseInt.ToString() + " MB";
return responseString;
}
public string GetCpuFrequency()
{
query = new ManagementObjectSearcher("SELECT * FROM Win32_Processor");
result = query.Get();
foreach (ManagementObject managementObject in result)
{
responseInt = Convert.ToInt32(managementObject["CurrentClockSpeed"].ToString());
}
responseString = responseInt.ToString() + " MHz";
return responseString;
}
}
Would this work for Remote Systems?
ReplyDeleteAs is posted, no. However using WMI you sure can get this to work.
ReplyDelete