日期:2014-05-18  浏览次数:20882 次

如何使用C#实现查看w3wp进程的信息
我现在可以用C#实现查看w3wp进程的各模块的信息和相关进程的状态,
有没有办法能够实现查看时打开什么页面时调用的w3wp进程,以及页面调用时使用的内存以及CPU占用情况

------解决方案--------------------
C# code

//===========================声明API========================================
        [DllImport("kernel32")]
        public static extern void GetWindowsDirectory(StringBuilder WinDir, int count);
        [DllImport("kernel32")]
        public static extern void GetSystemDirectory(StringBuilder SysDir, int count);
        [DllImport("kernel32")]
        public static extern void GetSystemInfo(ref CPU_INFO cpuinfo);
        [DllImport("kernel32")]
        public static extern void GlobalMemoryStatus(ref MEMORY_INFO meminfo);
        [DllImport("kernel32")]
        public static extern void GetSystemTime(ref SYSTEMTIME_INFO stinfo);
//============================================================================
//================定义CPU的信息结构===========================================
        [StructLayout(LayoutKind.Sequential)]
            public struct CPU_INFO
        {
            public uint dwOemId;//CPU的OEM
            public uint dwPageSize;//CPU的页面大小
            public uint lpMinimumApplicationAddress;
            public uint lpMaximumApplicationAddress;
            public uint dwActiveProcessorMask;
            public uint dwNumberOfProcessors;//CPU的个数
            public uint dwProcessorType;//CPU的类型
            public uint dwAllocationGranularity;
            public uint dwProcessorLevel;//CPU的等级
            public uint dwProcessorRevision;
        }


        //定义内存的信息结构
        [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;//剩余虚拟内存
        }


        //定义系统时间的信息结构
        [StructLayout(LayoutKind.Sequential)]
            public struct SYSTEMTIME_INFO
        {
            public ushort wYear;//年
            public ushort wMonth;//月
            public ushort wDayOfWeek;
            public ushort wDay;//日
            public ushort wHour;//时
            public ushort wMinute;//分
            public ushort wSecond;//秒
            public ushort wMilliseconds;
        }
//=========================================================================================
                                string ProcessName=[color=#FF0000]进行名称[/color];
                Process[] MyProcess=Process.GetProcessesByName(ProcessName);
                this.label26.Text="进程镜像名:"+MyProcess[0].ProcessName;
                this.label27.Text="进程ID;"+MyProcess[0].Id;
                this.label29.Text="启动线程数:"+MyProcess[0].Threads.Count.ToString();
                this.label28.Text="CPU占用时间:"+MyProcess[0].TotalProcessorTime.ToString();
                this.label30.Text="线程优先级:"+MyProcess[0].PriorityClass.ToString();
                this.label31.Text="启动时间:"+MyProcess[0].StartTime.ToLongTimeString();
                this.label32.Text="专用内存:"+(MyProcess[0].PrivateMemorySize/1024).ToString()+"K";
                this.label33.Text="峰顶虚拟内存:"+(MyProcess[0].PeakVirtualMemorySize/1024).ToString()+"K";
                this.label35.Text="峰顶分页内存:"+(MyProcess[0].PeakPagedMemorySize/1024).ToString()+"K";
                this.label34.Text="分页系统内存:"+(MyProcess[0].PagedSystemMemorySize/1024).ToString()+"K";
                this.label36.Text="分页内存:"+(MyProcess[0].PagedMemorySize/1024).ToString()+"K";
                this.label37.Text="未分页系统内存:"