string processor = "Win32_Processor";//类名
ManagementClass driveClass= new ManagementClass(processor);
Console.WriteLine(driveClass.GetQualifierValue("UUID"));
private static string GetUUID()
{
try
{
string uuid = string.Empty;
using (PowerShell PowerShellInstance = PowerShell.Create())
{
PowerShellInstance.AddScript("(get-wmiobject Win32_ComputerSystemProduct).UUID"); //OK
Collection<PSObject> PSOutput = PowerShellInstance.Invoke();
foreach (PSObject outputItem in PSOutput)
{
if (outputItem != null)
{
uuid += outputItem.BaseObject.ToString();
}
}
}
return uuid;
}
catch
{
return string.Empty;
}
}
private static string GetAsyncUUID()
{
try
{
string uuid = string.Empty;
using (PowerShell PowerShellInstance = PowerShell.Create())
{
PowerShellInstance.AddScript("(get-wmiobject Win32_ComputerSystemProduct).UUID"); //OK
PSDataCollection<PSObject> outputCollection = new PSDataCollection<PSObject>();
outputCollection.DataAdded += outputCollection_DataAdded;
PowerShellInstance.Streams.Error.DataAdded += Error_DataAdded;
IAsyncResult result = PowerShellInstance.BeginInvoke<PSObject, PSObject>(null, outputCollection);
while (result.IsCompleted == false)
{
Console.WriteLine("Waiting for pipeline to finish...");
Thread.Sleep(1000);
// While里面可以写上执行等待中的一些事情
}
foreach (PSObject outputItem in outputCollection)
{
if (outputItem != null)
{
uuid += outputItem.BaseObject.ToString();
}
}
}
return uuid;
}
catch
{
return string.Empty;
}
}
static void Error_DataAdded(object sender, DataAddedEventArgs e)
{
Console.WriteLine("An error was written to the Error stream!");
}
static void outputCollection_DataAdded(object sender, DataAddedEventArgs e)
{
Console.WriteLine("Object added to output.");
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有