您当前的位置:首页 > 养生 > 内容

managementobjectsearcher(C# 获取系统进程)

本文目录

  • C# 获取系统进程
  • C#用一个下拉列表,在里面显示所有电脑的盘符,急!~~~~
  • 怎么取得硬盘和内存的类型和厂商 C#语言编写,写重点代码简洁要简洁,谢谢

C# 获取系统进程

using System.Diagnostics;using System.Management;static void Main(string args){foreach (Process p in Process.GetProcesses()) { Console.Write(p.ProcessName); Console.Write(“----“); Console.WriteLine(GetProcessUserName(p.Id)); } Console.ReadKey();}private static string GetProcessUserName(int pID){ string text1 = null; SelectQuery query1 = new SelectQuery(“Select * from Win32_Process WHERE processID=“ + pID); ManagementObjectSearcher searcher1 = new ManagementObjectSearcher(query1); try { foreach (ManagementObject disk in searcher1.Get()) { ManagementBaseObject inPar = null; ManagementBaseObject outPar = null; inPar = disk.GetMethodParameters(“GetOwner“); outPar = disk.InvokeMethod(“GetOwner“, inPar, null); text1 = outPar[“User“].ToString(); break; } } catch { text1 = “SYSTEM“; } return text1;}

C#用一个下拉列表,在里面显示所有电脑的盘符,急!~~~~

我给你一个最简单的:先创建一个comboBox然后在Form1_Load里输入this.comboBox1.DataSource =System.IO.Directory .GetLogicalDrives ();

怎么取得硬盘和内存的类型和厂商 C#语言编写,写重点代码简洁要简洁,谢谢

以下源码来着网络,本人不拥有该源码的任何权利;且不愿承担刊登该源码的任何责任;如果我的行为侵犯了你的利益,请给我通知,我会第一时间维护你的权益;c# 获取系统基本信息 //cpu的编号 using System.Management; ManagementClass mc = new ManagementClass(“Win32_Processor“); ManagementObjectCollection moc = mc.GetInstances(); String strCpuID = null; foreach (ManagementObject mo in moc) { strCpuID = mo.Properties[“ProcessorId“].Value.ToString(); this.label1.Text = strCpuID; break; }//获取CPU基本信息 using System.Runtime.InteropServices; [DllImport(“kernel32 “)] public static extern void GetSystemInfo(ref CPU_INFO cpuinfo);//定义CPU的信息结构 [StructLayout(LayoutKind.Sequential)] public struct CPU_INFO { public uint dwOemId; public uint dwPageSize; public uint lpMinimumApplicationAddress; public uint lpMaximumApplicationAddress; public uint dwActiveProcessorMask; public uint dwNumberOfProcessors; public uint dwProcessorType; public uint dwAllocationGranularity; public uint dwProcessorLevel; public uint dwProcessorRevision; }private void Form1_Load(object sender, EventArgs e) { //调用GetSystemInfo函数获取CPU的相关信息 CPU_INFO CpuInfo; CpuInfo = new CPU_INFO(); GetSystemInfo(ref CpuInfo); string a = “本计算机中有 “ + CpuInfo.dwNumberOfProcessors.ToString()+ “个CPU “; string b = “CPU的类型为 “ + CpuInfo.dwProcessorType.ToString(); string c = “CPU等级为 “ + CpuInfo.dwProcessorLevel.ToString(); string d = “CPU的OEM ID为 “ + CpuInfo.dwOemId.ToString(); string e = “CPU中的页面大小为 “ + CpuInfo.dwPageSize.ToString(); }//获取物理内存 using System.Management;//注意需要引用 string st = ““; ManagementClass mc = new ManagementClass(“Win32_ComputerSystem“); ManagementObjectCollection moc = mc.GetInstances(); foreach (ManagementObject mo in moc) { st = mo[“TotalPhysicalMemory“].ToString(); }//显示卡信息 ManagementObjectSearcher searcher = new ManagementObjectSearcher(@“root\CIMV2“, “SELECT * FROM Win32_VideoController“); foreach (ManagementObject info in searcher.Get()) { string a = “适配器兼容性 “+ info[“AdapterCompatibility“].ToString(); string b = “适配器类型 “+ info[“AdapterDACType“].ToString(); string c = “视频模式描述“+info[“VideoModeDescription“].ToString(); string d = “字幕“+info[“Caption“].ToString(); string e = “目前比特每像素“+info[“CurrentBitsPerPixel“].ToString(); string f = “目前的水平分辨率“+info[“CurrentHorizontalResolution“].ToString(); string g = “视频处理器“+info[“VideoProcessor“].ToString(); string h = “最大刷新率“ + info[“MaxRefreshRate“].ToString(); string i = “设备ID“ + info[“DeviceID“].ToString(); string j = “描述“ + info[“Description“].ToString(); }//获取分区信息 using System.Management; private void button1_Click(object sender, EventArgs e) { WqlObjectQuery wmiquery = new WqlObjectQuery(“SELECT * FROM Win32_LogicalDisk WHERE DeviceID = ’e:’“); ManagementObjectSearcher wmifind = new ManagementObjectSearcher(wmiquery); foreach (ManagementObject mobj in wmifind.Get()) { string a = (“磁盘类型: “ + mobj[“Description“].ToString()); string b = (“分区类型: “ + mobj[“FileSystem“].ToString()); string c = (“可用空间: “ + mobj[“FreeSpace“].ToString()); string d = (“实际大小: “ + mobj[“Size“].ToString()); } }//获取主板信息 using System.Management; ManagementObjectSearcher my = new ManagementObjectSearcher(“SELECT * FROM Win32_BaseBoard“); foreach (ManagementObject share in my.Get()) { string a = “主板制造商:“ + share[“Manufacturer“].ToString(); string b = “产品:“ + share[“Product“].ToString(); string c = “主板序列号:“ + share[“SerialNumber“].ToString(); }//获取IP地址 using System.Management; string st = ““; ManagementClass mc = new ManagementClass(“Win32_NetworkAdapterConfiguration“); ManagementObjectCollection moc = mc.GetInstances(); foreach (ManagementObject mo in moc) { if ((bool)mo[“IPEnabled“] == true) { //st=mo[“IpAddress“].ToString(); System.Array ar; ar = (System.Array)(mo.Properties[“IpAddress“].Value); st = ar.GetValue(0).ToString(); String ipadd = st; break; } }//获取进程详细信息 using System.Diagnostics; string s = ““; System.Int32 processid; Process process; //Retrieve the additional information about a specific process processid = Int32.Parse(this.textBox1.Text); process = System.Diagnostics.Process.GetProcessById(processid); s = s + “该进程的总体优先级类别:“ + Convert.ToString(process.PriorityClass) + “ \r\n“; s = s + “由该进程打开的句柄数:“ + process.HandleCount + “\r\n“; s = s + “该进程的主窗口标题:“ + process.MainWindowTitle + “\r\n“; s = s + “ 该进程允许的最小工作集大小:“ + process.MinWorkingSet.ToString() + “ \r\n“; s = s + “该进程允许的最大工作集大小:“ + process.MaxWorkingSet.ToString() + “ \r\n“; s = s + “该进程的分页内存大小:“ + process.PagedMemorySize + “\r\n“; s = s + “该进程的峰值分页内存大小:“ + process.PeakPagedMemorySize + “\r\n“; System.Windows.Forms.MessageBox.Show(s); 为了避免异常崩溃 建议放在 TRY 里运行//获取系统的启动日期和安装日期. System.Management.ObjectQuery MyQuery=new ObjectQuery(“SELECT * FROM Win32_OperatingSystem“); System.Management.ManagementScope MyScope=new ManagementScope(); ManagementObjectSearcher MySearch=new ManagementObjectSearcher(MyScope,MyQuery); ManagementObjectCollection MyCollection=MySearch.Get(); string StrInfo=““; foreach(ManagementObject MyObject in MyCollection) { StrInfo=MyObject.GetText(TextFormat.Mof); } string InstallDate=StrInfo.Substring(StrInfo.LastIndexOf(“InstallDate“)+15,14); string LastBootUpTime=StrInfo.Substring(StrInfo.LastIndexOf(“LastBootUpTime“)+18,14); string a =InstallDate; string b =LastBootUpTime;


声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,谢谢。

上一篇: 怎么开启省电模式?开启省电模式怎么开启

下一篇: 多屏互动浏览器非法(苹果4s中多屏互动浏览器怎么看不了片子了其他的电影能看)



猜你感兴趣

推荐阅读

网站内容来自网络,如有侵权请联系我们,立即删除! | 软文发布 | 粤ICP备2021106084号