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

怎么取得硬盘和内存的型号(不是序列号)和厂商?要代码不要思路,急哇,就没有一个人会。什么WMI,API,写出来看了才知道,都取不到的... 怎么取得硬盘和内存的型号(不是序列号)和厂商?
要代码不要思路,急哇,就没有一个人会。什么WMI,API,写出来看了才知道,都取不到的
展开
 我来答
百度网友130561a
2011-07-17 · TA获得超过380个赞
知道小有建树答主
回答量:324
采纳率:0%
帮助的人:177万
展开全部
以下源码来着网络,本人不拥有该源码的任何权利;且不愿承担刊登该源码的任何责任;如果我的行为侵犯了你的利益,请给我通知,我会第一时间维护你的权益;

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;
追问
你的内存厂商得不到吧?
琦夏侯岚5o
2011-07-18 · TA获得超过5.9万个赞
知道大有可为答主
回答量:2.8万
采纳率:0%
帮助的人:3965万
展开全部
用WMI实现
可以去搜一下相关的操作方法,不是很难。
只要调用一个API函数就能获得
以下源码来着网络,本人不拥有该源码的任何权利;且不愿承担刊登该源码的任何责任;如果我的行为侵犯了你的利益,请给我通知,我会第一时间维护你的权益;

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;
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
yujian1125
2011-07-14 · TA获得超过884个赞
知道小有建树答主
回答量:330
采纳率:0%
帮助的人:246万
展开全部
用WMI实现
可以去搜一下相关的操作方法,不是很难。
只要调用一个API函数就能获得
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
义淡丝5312
2011-07-13 · TA获得超过5.6万个赞
知道大有可为答主
回答量:3.2万
采纳率:0%
帮助的人:4037万
展开全部
我靠,怎么就没一个回答哇,伤心了
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式