PDA

View Full Version : گرفتن مشخصات سخت افزار در ویندوز xp



Alfred188
شنبه 04 آذر 1391, 12:13 عصر
سلام،
من از کد زیر برای گرفتن مشخصات سخت افزار استفاده می کنم با ویندوز 7 مشکلی نداره ولی تو xp جواب نمی ده

ManagementObjectSearcher mosDisks = new ManagementObjectSearcher("SELECT * FROM Win32_Processor");
foreach (ManagementObject moDisk in mosDisks.Get())
{
code = moDisk1["ProcessorID"].ToString();
}


به نظرتون مشکل از کجاست؟ چه باید کنم؟
ممنون

farghabil
شنبه 04 آذر 1391, 12:28 عصر
95518

این کد نمونه رو نگاه کن
من با این نمونه واسه برنانه ها سریال تعریف میکنم که تو هر سیستم مثلا فقط یکبار نصب بشه
میاد کد سخت افزار ها رو میگیره

Alfred188
شنبه 04 آذر 1391, 13:44 عصر
95518

این کد نمونه رو نگاه کن
من با این نمونه واسه برنانه ها سریال تعریف میکنم که تو هر سیستم مثلا فقط یکبار نصب بشه
میاد کد سخت افزار ها رو میگیره

ممنون از توجه شما دوست عزیز، ولی فکر کنم اشتباه فرستادید این فقط تاریخ می ده!

arefba
شنبه 04 آذر 1391, 15:36 عصر
این اون چیزی هست که میخوای
www.codeproject.com/KB/system/GetHardwareInformation.aspx (http://barnamenevis.org/www.codeproject.com/KB/system/GetHardwareInformation.aspx)

dabirsiaghi
شنبه 04 آذر 1391, 16:05 عصر
بنده از این کد در پروژه هام استفاده میکنم.البته بیشتر برای قفل استفاده میکنم.


private static string identifier
(string wmiClass, string wmiProperty, string wmiMustBeTrue)
{
string result = "";
System.Management.ManagementClass mc =
new System.Management.ManagementClass(wmiClass);
System.Management.ManagementObjectCollection moc = mc.GetInstances();
foreach (System.Management.ManagementObject mo in moc)
{
if (mo[wmiMustBeTrue].ToString() == "True")
{
//Only get the first one
if (result == "")
{
try
{
result = mo[wmiProperty].ToString();
break;
}
catch
{
}
}
}
}
return result;
}
private static string identifier(string wmiClass, string wmiProperty)
{
string result = "";
System.Management.ManagementClass mc =
new System.Management.ManagementClass(wmiClass);
System.Management.ManagementObjectCollection moc = mc.GetInstances();
foreach (System.Management.ManagementObject mo in moc)
{
//Only get the first one
if (result == "")
{
try
{
result = mo[wmiProperty].ToString();
break;
}
catch
{
}
}
}
return result;
}
private static string cpuId()
{
//Uses first CPU identifier available in order of preference
//Don't get all identifiers, as it is very time consuming
string retVal = identifier("Win32_Processor", "UniqueId");
if (retVal == "") //If no UniqueID, use ProcessorID
{
retVal = identifier("Win32_Processor", "ProcessorId");
if (retVal == "") //If no ProcessorId, use Name
{
retVal = identifier("Win32_Processor", "Name");
if (retVal == "") //If no Name, use Manufacturer
{
retVal = identifier("Win32_Processor", "Manufacturer");
}
//Add clock speed for extra security
retVal += identifier("Win32_Processor", "MaxClockSpeed");
}
}
return retVal;
}
private static string biosId()
{
return identifier("Win32_BIOS", "Manufacturer")
+ identifier("Win32_BIOS", "SMBIOSBIOSVersion")
+ identifier("Win32_BIOS", "IdentificationCode")
+ identifier("Win32_BIOS", "SerialNumber")
+ identifier("Win32_BIOS", "ReleaseDate")
+ identifier("Win32_BIOS", "Version");
}
private static string diskId()
{
return identifier("Win32_DiskDrive", "Model")
+ identifier("Win32_DiskDrive", "Manufacturer")
+ identifier("Win32_DiskDrive", "Signature")
+ identifier("Win32_DiskDrive", "TotalHeads");
}
private static string baseId()
{
return identifier("Win32_BaseBoard", "Model")
+ identifier("Win32_BaseBoard", "Manufacturer")
+ identifier("Win32_BaseBoard", "Name")
+ identifier("Win32_BaseBoard", "SerialNumber");
//+ "Sun Mar 11 11:28:58 2007";
}
private static string videoId()
{
return identifier("Win32_VideoController", "DriverVersion")
+ identifier("Win32_VideoController", "Name");
}
private static string macId()
{
return identifier("Win32_NetworkAdapterConfiguration",
"MACAddress", "IPEnabled");
}

farghabil
شنبه 04 آذر 1391, 20:02 عصر
ممنون از توجه شما دوست عزیز، ولی فکر کنم اشتباه فرستادید این فقط تاریخ می ده!

اخ اخ ببخشید اشتباه آپ کردم. تشابه اسمی بود.
همون مطلبی که آقای arefba (http://barnamenevis.org/member.php?99613-arefba) فرمودند دقیقا همونی هستش که من میخواستم بگم

josh simpson
دوشنبه 11 دی 1391, 16:37 عصر
لیست کامل کلاس هایی که میتونید برای System.Management.ManagementClass استفاده کنید:

http://msdn.microsoft.com/en-us/library/windows/desktop/aa394084%28v=vs.85%29.aspx