1) Мне нежно узнать какой видавоз установлен. Нужно узнать через реестр.
2) Нужно узнать имеет или нет текущий юзер права админа.
3) Сколько памяти свободно на харде. И сколько Всего оперативной памяти.
4) Какой прцессор установлен.
5) Какая температура процессора.
Заранее всем СПАСИБО.
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Management;
using System.Runtime.InteropServices;
using System.Diagnostics;
using My.Computer.WMI;
namespace ConsoleApplication9
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(string.Format("OS = {0}", Environment.OSVersion));
Console.WriteLine(string.Format("Processor count = {0}", Environment.ProcessorCount));
HardInfoOut();
Ram_Available();
foreach (ProcessorInfo pInfo in ProcessorInfo.CPUs)
{
Console.WriteLine("CPU Name = {0}, CPU load percent = {1} ", pInfo.Name, pInfo.LoadPercentage);
}
System.Security.Principal.WindowsIdentity wi = System.Security.Principal.WindowsIdentity.GetCurrent();
System.Security.Principal.WindowsPrincipal wp = new System.Security.Principal.WindowsPrincipal(wi);
if (wp.IsInRole("Administrators"))
Console.WriteLine(wp.Identity.Name + " is an Administrator!");
}
public struct MemoryStatus
{
public uint Length; //Length of struct
public uint MemoryLoad; //Value from 0-100 represents memory usage
public uint TotalPhysical;
public uint AvailablePhysical;
public uint TotalPageFile;
public uint AvailablePageFile;
public uint TotalVirtual;
public uint AvailableVirtual;
}
[DllImport("kernel32.dll")]
public static extern void GlobalMemoryStatus(out MemoryStatus stat);
private static void Ram_Available()
{
ManagementScope oMs = new ManagementScope();
ObjectQuery oQuery = new ObjectQuery("SELECT Capacity, Caption FROM Win32_PhysicalMemory");
ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(oMs, oQuery);
ManagementObjectCollection oReturnCollection = oSearcher.Get();
foreach (ManagementObject oReturn in oReturnCollection)
{
Console.WriteLine("Size: " + oReturn["Capacity"] + " Caption " + oReturn["Caption"]);
}
PerformanceCounter ramCounter = new PerformanceCounter("Memory", "Available MBytes");
Console.WriteLine(string.Format("Ram available {0}", ramCounter.NextValue() + "Mb"));
MemoryStatus stat;
GlobalMemoryStatus(out stat);
Microsoft.VisualBasic.Devices.ComputerInfo myCompInfo = new Microsoft.VisualBasic.Devices.ComputerInfo();
Console.WriteLine("Physical Memory {0}", myCompInfo.TotalPhysicalMemory);
}
private static void HardInfoOut()
{
foreach (DriveInfo dInfo in DriveInfo.GetDrives())
{
if (dInfo.DriveType == DriveType.Ram) {
Console.WriteLine("RAM {0}; free space = {1}; total space = {2}", dInfo.Name, dInfo.TotalFreeSpace, dInfo.TotalSize);
}
if (dInfo.DriveType != DriveType.Fixed)
{
continue;
}
Console.WriteLine("Disk {0}; free space = {1}; total space = {2}", dInfo.Name, dInfo.TotalFreeSpace, dInfo.TotalSize);
}
}
}
}
using System;
using System.Management;
namespace My.Computer.WMI
{
/// <summary>
/// Provide information for each processor
/// </summary>
public class ProcessorInfo
{
public object Architecture;
public object Availability;
public object Caption ;
public object CpuStatus;
public object CreationClassName;
public object CurrentClockSpeed;
public object CurrentVoltage;
public object DataWidth;
public object Description;
public object DeviceID;
public object ExtClock;
public object Family;
public object InstallDate;
public object L2CacheSize;
public object L2CacheSpeed;
public object LastErrorCode;
public object Level;
public object LoadPercentage;
public object Manufacturer;
public object MaxClockSpeed;
public object Name;
public object OtherFamilyDescription;
public object PNPDeviceID;
public object PowerManagementSupported;
public object ProcessorId;
public object ProcessorType;
public object Revision;
public object Role;
public object SocketDesignation;
public object Status;
public object StatusInfo;
public object Stepping;
public object SystemName;
public object UniqueId;
public object Version;
public object VoltageCaps;
/// <summary>
/// Get all the necessary information about each processor
/// </summary>
public static ProcessorInfo[] CPUs
{
get
{
// Get the information for each processor.
string query = "Select * From Win32_Processor";
// Create a searcher object.
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
// Get the results.
ManagementObjectCollection results = searcher.Get();
// Create a strong-typed ProcessorInfo array.
ProcessorInfo[] listCPUs = new ProcessorInfo[results.Count];
int index = 0;
// Copy the results to the strong-typed ProcessorInfo.
foreach (ManagementObject entryCurrent in results)
{
// Create a new info object.
ProcessorInfo cpuInfo = new ProcessorInfo();
// Set the properties.
cpuInfo.Architecture = entryCurrent["Architecture"];
cpuInfo.Availability = entryCurrent["Availability"];
cpuInfo.Caption = entryCurrent["Caption"];
cpuInfo.CpuStatus = entryCurrent["CpuStatus"];
cpuInfo.CreationClassName = entryCurrent["CreationClassName"];
cpuInfo.CurrentClockSpeed = entryCurrent["CurrentClockSpeed"];
cpuInfo.CurrentVoltage = entryCurrent["CurrentVoltage"];
cpuInfo.DataWidth = entryCurrent["DataWidth"];
cpuInfo.Description = entryCurrent["Description"];
cpuInfo.DeviceID = entryCurrent["DeviceID"];
cpuInfo.ExtClock = entryCurrent["ExtClock"];
cpuInfo.Family = entryCurrent["Family"];
cpuInfo.InstallDate = entryCurrent["InstallDate"];
cpuInfo.L2CacheSize = entryCurrent["L2CacheSize"];
cpuInfo.L2CacheSpeed = entryCurrent["L2CacheSpeed"];
cpuInfo.LastErrorCode = entryCurrent["LastErrorCode"];
cpuInfo.Level = entryCurrent["Level"];
cpuInfo.LoadPercentage = entryCurrent["LoadPercentage"];
cpuInfo.Manufacturer = entryCurrent["Manufacturer"];
cpuInfo.MaxClockSpeed = entryCurrent["MaxClockSpeed"];
cpuInfo.Name = entryCurrent["Name"];
cpuInfo.OtherFamilyDescription = entryCurrent["OtherFamilyDescription"];
cpuInfo.PNPDeviceID = entryCurrent["PNPDeviceID"];
cpuInfo.PowerManagementSupported = entryCurrent["PowerManagementSupported"];
cpuInfo.ProcessorId = entryCurrent["ProcessorId"];
cpuInfo.ProcessorType = entryCurrent["ProcessorType"];
cpuInfo.Revision = entryCurrent["Revision"];
cpuInfo.Role = entryCurrent["Role"];
cpuInfo.SocketDesignation = entryCurrent["SocketDesignation"];
cpuInfo.Status = entryCurrent["Status"];
cpuInfo.StatusInfo = entryCurrent["StatusInfo"];
cpuInfo.Stepping = entryCurrent["Stepping"];
cpuInfo.SystemName = entryCurrent["SystemName"];
cpuInfo.UniqueId = entryCurrent["UniqueId"];
cpuInfo.Version = entryCurrent["Version"];
cpuInfo.VoltageCaps = entryCurrent["VoltageCaps"];
listCPUs[index] = cpuInfo;
index += 1;
}
return listCPUs;
}
}
}
}
Здравствуйте, GodHell, Вы писали:
GH>1) Мне нежно узнать какой видавоз установлен. Нужно узнать через реестр.
System.Environment.OSVersion
GH>2) Нужно узнать имеет или нет текущий юзер права админа.
using System;
using System.Security.Principal;
class Program
{
static void Main() {
WindowsPrincipal principal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
bool isAdministrator = principal.IsInRole(WindowsBuiltInRole.Administrator);
}
}
GH>3) Сколько памяти свободно на харде. И сколько Всего оперативной памяти.
GH>4) Какой прцессор установлен.
GH>5) Какая температура процессора.
Всё, кроме количества свободной на харде памяти, можно спросить у
WMI