获取服务器数据cpu序列和日期 [英] Get server data cpu serial and date
本文介绍了获取服务器数据cpu序列和日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的专家;
我正在使用实体框架和sql数据库工作c#windows应用程序项目我需要获取服务器cpu序列和当前日期但是从具有我连接的数据库的服务器不是来自本地电脑
我的尝试:
Dear experts ;
i'm work on c# windows application project using entity framework and sql database i need to get the server cpu serial and current date but from the server that have database which i connected not from local pc
What I have tried:
public static string GetMotherBoardID()
{
string cpuInfo = string.Empty;
ManagementClass mc = new ManagementClass("win32_processor");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
if (cpuInfo == "")
{
//Get only the first CPU's ID
cpuInfo = mo.Properties["processorID"].Value.ToString();
break;
}
}
return cpuInfo;
}
推荐答案
我认为你走在正确的轨道上。这只是确定要查询的部分的问题。
这可以改进,但它是一个开始:
It looks to me like you are on the right track. It is just a matter of determining which pieces to query.
This can be improved on, but its a start:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Management;
using System.IO;
namespace ConsoleApp2
{
class Program
{
public static bool GetComputerInfo(string machine, string win32object, string attributename)
{
bool bReturnValue = true;
try
{
// Use the Storage management scope
ManagementScope scope = new ManagementScope(
@\ \ {机} \ROOT\cimv2\" );
//定义查询
ObjectQuery query = new ObjectQuery(
@"\\{machine}\ROOT\cimv2"); // Define the query ObjectQuery query = new ObjectQuery(
SELECT * FROM {win32object});
//创建搜索
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope,query);
//获取WMI对象的集合
ManagementObjectCollection queryCollection = searcher.Get();
//枚举集合。
foreach(queryObject在queryCollection中)
{
//访问WMI对象的属性
Console.WriteLine(
"SELECT * FROM {win32object}"); // create the search ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query); //get a collection of WMI objects ManagementObjectCollection queryCollection = searcher.Get(); //enumerate the collection. foreach (ManagementObject m in queryCollection) { // access properties of the WMI object Console.WriteLine(
这篇关于获取服务器数据cpu序列和日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文