Process[] myProcesses = Process.GetProcesses(); "拒绝访问"

hb9191 2004-03-23 11:36:45
Process[] myProcesses = Process.GetProcesses();执行出错:
异常详细信息: System.ComponentModel.Win32Exception: 拒绝访问。
怎么处理?
...全文
89 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
dahuzizyd 2004-03-23
  • 打赏
  • 举报
回复
编辑注册表中的引用记数器的设置:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\PerfProc\Performance



remove an entry named "Disable Performance Counters" or set it to 0
HNU 2004-03-23
  • 打赏
  • 举报
回复

SHOW YOUR 全部或者部分代码
hb9191 2004-03-23
  • 打赏
  • 举报
回复
还是同样的错!
HNU 2004-03-23
  • 打赏
  • 举报
回复


using System.Diagnostics;
using Microsoft.Win32 ;
根据网友提供代码,逆向画出来的。包含CPU使用率、内存使用率、虚拟内存使用率、内存总量等。数据比较符合靠谱。 ***************************************************************************** using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Diagnostics; using System.Threading; using System.Runtime.InteropServices; using System.Management; namespace Cpu_Test { public partial class Form1 : Form { public Form1() { InitializeComponent(); } Process[] MyProcesses; Thread td; private void myUser() { ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from Win32_Processor"); foreach (ManagementObject myobject in searcher.Get()) { tssluse.Text = myobject["LoadPercentage"].ToString() + " %"; lblCPU.Text = myobject["LoadPercentage"].ToString() + " %"; mheight = Convert.ToInt32(myobject["LoadPercentage"].ToString()); if (mheight == 100) panel3.Height = 100; CreateImage(); Memory(); } } private void Memory() { Microsoft.VisualBasic.Devices.Computer myInfo = new Microsoft.VisualBasic.Devices.Computer(); //获取物理内存总量 pbMemorySum.Maximum = Convert.ToInt32(myInfo.Info.TotalPhysicalMemory / 1024 / 1024); pbMemorySum.Value = Convert.ToInt32(myInfo.Info.TotalPhysicalMemory / 1024 / 1024); lblSum.Text = (myInfo.Info.TotalPhysicalMemory / 1024).ToString(); //获取可用物理内存总量 pbMemoryUse.Maximum = Convert.ToInt32(myInfo.Info.TotalPhysicalMemory / 1024 / 1024); pbMemoryUse.Value = Convert.ToInt32(myInfo.Info.AvailablePhysicalMemory / 1024 / 1024); lblMuse.Text = (myInfo.Info.AvailablePhysicalMemory / 1024).ToString(); //获取虚拟内存总量 pbVmemorysum.Maximum = Convert.ToInt32(myInfo.Info.TotalVirtualMemory / 1024 / 1024); pbVmemorysum.Value = Convert.ToInt32(myInfo.Info.TotalVirtualMemory / 1024 / 1024); lblVinfo.Text = (myInfo.Info.TotalVirtualMemory / 1024).ToString(); //获取可用虚拟内存总量 pbVmemoryuse.Maximum = Convert.ToInt32(myInfo.Info.TotalVirtualMemory / 1024 / 1024); pbVmemoryuse.Value = Convert.ToInt32(myInfo.Info.AvailableVirtualMemory / 1024 / 1024); lblVuse.Text = (myInfo.Info.AvailableVirtualMemory / 1024).ToString(); } private void Form1_Load(object sender, EventArgs e) { CheckForIllegalCrossThreadCalls = false; MyProcesses = Process.GetProcesses(); //tsslNum.Text = "进程数: "; tsslNum.Text = "进程数: "+ MyProcesses.Length.ToString()+ " CPU使用: "; myUser(); } private void timer1_Tick(object sender, EventArgs e) { Control.CheckForIllegalCrossThreadCalls = false; MyProcesses = Process.GetProcesses(); tsslNum.Text = "进程数: " + MyProcesses.Length.ToString() + " | CPU使用:"; td = new Thread(new ThreadStart(myUser)); td.Start(); } private void Form1_FormClosed(object sender, FormClosedEventArgs e) { if (td != null) { td.Abort(); } } int mheight = 0; private void CreateImage() { int i = panel3.Height / 100; Bitmap image = new Bitmap(panel3.Width, panel3.Height); Graphics g = Graphics.FromImage(image); g.Clear(Color.Green); SolidBrush mybrush = new SolidBrush(Color.Lime); g.FillRectangle(mybrush, 0, panel3.Height - mheight * i, 26, mheight * i); panel3.BackgroundImage = image; } } }

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧