c# 如何获取某一个进程的cpu和内存使用情况 35
类似Windows资源管理器某一个进程的cpu和内存使用情况..不好意思,刚注册很穷不好意思,我是要某一个进程的cpu和内存使用情况而不是整个系统的...
类似Windows资源管理器某一个进程的cpu和内存使用情况..
不好意思,刚注册很穷
不好意思,我是要某一个进程的cpu和内存使用情况 而不是整个系统的 展开
不好意思,刚注册很穷
不好意思,我是要某一个进程的cpu和内存使用情况 而不是整个系统的 展开
展开全部
//cpu频率
using Microsoft.Win32;
private int GetCPUFrequency()
{
RegistryKey rk = Registry.LocalMachine.OpenSubKey(@"HARDWARE\DESCRIPTION\System\CentralProcessor\0");
object obj = rk.GetValue("~MHz");
int CPUFrequency = (int)obj;
return CPUFrequency;
}
//////////////////////////////////
//磁盘空间 Management
using System.Management;
private long GetFreeDiskSpace()
{
ManagementObject disk = new ManagementObject(
"win32_logicaldisk.deviceid=\"d:\"");
disk.Get();
string totalByte = disk["FreeSpace"].ToString();
long freeDiskSpaceMb = Convert.ToInt64(totalbyte)/1024/1024;
return freeDiskSpaceMb;
}
/////////////////////
//内存信息
using System;
using System.Text;
using System.Runtime.InteropServices;
namespace ConsoleApplication1
{
/**//// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
[StructLayout(LayoutKind.Sequential)]
public struct MEMORY_INFO
{
public uint dwLength;
public uint dwMemoryLoad;
public uint dwTotalPhys;
public uint dwAvailPhys;
public uint dwTotalPageFile;
public uint dwAvailPageFile;
public uint dwTotalVirtual;
public uint dwAvailVirtual;
}
[DllImport("kernel32")]
public static extern void GlobalMemoryStatus(ref MEMORY_INFO meminfo);
public static int Main(string[] args)
{
Class1 class1 = new Class1();
class1.GetMemoryStatus();
return 0;
}
private void GetMemoryStatus()
{
MEMORY_INFO MemInfo;
MemInfo = new MEMORY_INFO();
GlobalMemoryStatus(ref MemInfo);
long totalMb = Convert.ToInt64( MemInfo.dwTotalPhys.ToString())/1024/1024;
long avaliableMb = Convert.ToInt64( MemInfo.dwAvailPhys.ToString())/1024/1024;
Console.WriteLine( "物理内存共有" + totalMb + " MB");
Console.WriteLine( "可使用的物理内存有" + avaliableMb +" MB");
}
}
//////////////////////////////
//cpu名字
using Microsoft.Win32;
private string GetCPUName()
{
RegistryKey rk = Registry.LocalMachine.OpenSubKey(@"HARDWARE\DESCRIPTION\System\CentralProcessor\0");
object obj = rk.GetValue("ProcessorNameString");
string CPUName = (string)obj;
return CPUName.TrimStart();
}
///////////////////////
//OS版本
using System;
namespace determineOS_CS
{
class Class1
{
static void Main(string[] args)
{
// Get OperatingSystem information from the system namespace.
System.OperatingSystem osInfo =System.Environment.OSVersion;
// Determine the platform.
switch(osInfo.Platform)
{
// Platform is Windows 95, Windows 98,
// Windows 98 Second Edition, or Windows Me.
case System.PlatformID.Win32Windows:
switch (osInfo.Version.Minor)
{
case 0:
Console.WriteLine ("Windows 95");
break;
case 10:
if(osInfo.Version.Revision.ToString()=="2222A")
Console.WriteLine("Windows 98 Second Edition");
else
Console.WriteLine("Windows 98");
break;
case 90:
Console.WriteLine("Windows Me");
break;
}
break;
// Platform is Windows NT 3.51, Windows NT 4.0, Windows 2000,
// or Windows XP.
case System.PlatformID.Win32NT:
switch(osInfo.Version.Major)
{
case 3:
Console.WriteLine("Windows NT 3.51");
break;
case 4:
Console.WriteLine("Windows NT 4.0");
break;
case 5:
if (osInfo.Version.Minor==0)
Console.WriteLine("Windows 2000");
else
Console.WriteLine("Windows XP");
break;
}break;
}
Console.ReadLine ();
}
}
}
嘎嘎
using Microsoft.Win32;
private int GetCPUFrequency()
{
RegistryKey rk = Registry.LocalMachine.OpenSubKey(@"HARDWARE\DESCRIPTION\System\CentralProcessor\0");
object obj = rk.GetValue("~MHz");
int CPUFrequency = (int)obj;
return CPUFrequency;
}
//////////////////////////////////
//磁盘空间 Management
using System.Management;
private long GetFreeDiskSpace()
{
ManagementObject disk = new ManagementObject(
"win32_logicaldisk.deviceid=\"d:\"");
disk.Get();
string totalByte = disk["FreeSpace"].ToString();
long freeDiskSpaceMb = Convert.ToInt64(totalbyte)/1024/1024;
return freeDiskSpaceMb;
}
/////////////////////
//内存信息
using System;
using System.Text;
using System.Runtime.InteropServices;
namespace ConsoleApplication1
{
/**//// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
[StructLayout(LayoutKind.Sequential)]
public struct MEMORY_INFO
{
public uint dwLength;
public uint dwMemoryLoad;
public uint dwTotalPhys;
public uint dwAvailPhys;
public uint dwTotalPageFile;
public uint dwAvailPageFile;
public uint dwTotalVirtual;
public uint dwAvailVirtual;
}
[DllImport("kernel32")]
public static extern void GlobalMemoryStatus(ref MEMORY_INFO meminfo);
public static int Main(string[] args)
{
Class1 class1 = new Class1();
class1.GetMemoryStatus();
return 0;
}
private void GetMemoryStatus()
{
MEMORY_INFO MemInfo;
MemInfo = new MEMORY_INFO();
GlobalMemoryStatus(ref MemInfo);
long totalMb = Convert.ToInt64( MemInfo.dwTotalPhys.ToString())/1024/1024;
long avaliableMb = Convert.ToInt64( MemInfo.dwAvailPhys.ToString())/1024/1024;
Console.WriteLine( "物理内存共有" + totalMb + " MB");
Console.WriteLine( "可使用的物理内存有" + avaliableMb +" MB");
}
}
//////////////////////////////
//cpu名字
using Microsoft.Win32;
private string GetCPUName()
{
RegistryKey rk = Registry.LocalMachine.OpenSubKey(@"HARDWARE\DESCRIPTION\System\CentralProcessor\0");
object obj = rk.GetValue("ProcessorNameString");
string CPUName = (string)obj;
return CPUName.TrimStart();
}
///////////////////////
//OS版本
using System;
namespace determineOS_CS
{
class Class1
{
static void Main(string[] args)
{
// Get OperatingSystem information from the system namespace.
System.OperatingSystem osInfo =System.Environment.OSVersion;
// Determine the platform.
switch(osInfo.Platform)
{
// Platform is Windows 95, Windows 98,
// Windows 98 Second Edition, or Windows Me.
case System.PlatformID.Win32Windows:
switch (osInfo.Version.Minor)
{
case 0:
Console.WriteLine ("Windows 95");
break;
case 10:
if(osInfo.Version.Revision.ToString()=="2222A")
Console.WriteLine("Windows 98 Second Edition");
else
Console.WriteLine("Windows 98");
break;
case 90:
Console.WriteLine("Windows Me");
break;
}
break;
// Platform is Windows NT 3.51, Windows NT 4.0, Windows 2000,
// or Windows XP.
case System.PlatformID.Win32NT:
switch(osInfo.Version.Major)
{
case 3:
Console.WriteLine("Windows NT 3.51");
break;
case 4:
Console.WriteLine("Windows NT 4.0");
break;
case 5:
if (osInfo.Version.Minor==0)
Console.WriteLine("Windows 2000");
else
Console.WriteLine("Windows XP");
break;
}break;
}
Console.ReadLine ();
}
}
}
嘎嘎
展开全部
发放如下:
public void ProcessName(string ProceName)
{ Process[] process = Process.GetProcesses();
foreach (Process pres in process)
{
if (pres.ProcessName == ProceName)
{
//获取指定进程内存使用情况
pres.WorkingSet;
//获取指定进程分配的物理内存量
pres.WorkingSet64;
//获取指定进程用户处理器时间
pres.UserProcessorTime;
//获取指定进程用户处理器总时间
pres.TotalProcessorTime;
}
}
}
调用的时候
ProcessName(进程名);
public void ProcessName(string ProceName)
{ Process[] process = Process.GetProcesses();
foreach (Process pres in process)
{
if (pres.ProcessName == ProceName)
{
//获取指定进程内存使用情况
pres.WorkingSet;
//获取指定进程分配的物理内存量
pres.WorkingSet64;
//获取指定进程用户处理器时间
pres.UserProcessorTime;
//获取指定进程用户处理器总时间
pres.TotalProcessorTime;
}
}
}
调用的时候
ProcessName(进程名);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
process.WorkingSet64 / 1000 //这个获得的是内存的使用情况,单位KB
PerformanceCounter ProcessorUsage = new PerformanceCounter();//定义获取CPU使用率的性能计数器
ProcessorUsage.CategoryName = "Processor";
ProcessorUsage.CounterName = "% Processor Time";
ProcessorUsage.InstanceName = "_Toal";
ProcessorUsage.MachineName = ".";
this.lblCpu.Text = "CPU 使用:"+ProcessorUsage.NextValue().ToString() + "%";
PerformanceCounter ProcessorUsage = new PerformanceCounter();//定义获取CPU使用率的性能计数器
ProcessorUsage.CategoryName = "Processor";
ProcessorUsage.CounterName = "% Processor Time";
ProcessorUsage.InstanceName = "_Toal";
ProcessorUsage.MachineName = ".";
this.lblCpu.Text = "CPU 使用:"+ProcessorUsage.NextValue().ToString() + "%";
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
请MSDN
参考Process
类
参考Process
类
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
下载个优化大师,可以看到你所需要的东东
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询