Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Monday, August 24, 2009 2:58 PM | 2 votes
public static string GetMotherBoardID()
{
string mbInfo = String.Empty;
//Get motherboard's serial number
ManagementObjectSearcher mbs = new ManagementObjectSearcher("Select * From Win32_BaseBoard");
foreach (ManagementObject mo in mbs.Get())
{
mbInfo += mo["SerialNumber"].ToString();
}
return mbInfo;
}
Above are the codes I'd like to distribute with my winform application to get the serial number of the motherboard but My codes always return empty string. What might be wrong with this?
All replies (10)
Monday, August 24, 2009 3:33 PM ✅Answered | 3 votes
Not sure that ManageObject can get to the info 100% of the time. Your method works on my machine. Here's another way to try it:
public static string GetMotherBoardID()
{
string mbInfo = String.Empty;
ManagementScope scope = new ManagementScope("\\\\" + Environment.MachineName + "\\root\\cimv2");
scope.Connect();
ManagementObject wmiClass = new ManagementObject(scope, new ManagementPath("Win32_BaseBoard.Tag=\"Base Board\""), new ObjectGetOptions());
foreach (PropertyData propData in wmiClass.Properties)
{
if (propData.Name == "SerialNumber")
mbInfo = String.Format("{0,-25}{1}", propData.Name, Convert.ToString(propData.Value));
}
return mbInfo;
}
Also, do you have any domain policy restrictions that may prevent you from getting this info? おろ?
Monday, August 24, 2009 5:37 PM
Thanks. Your method returns "SerialNumber ". It's a long empty string at the end.
The winform is being distributed to end-user so I have no control to know whether end-user has any restriction. I just need a reliable method to return MB serial number.
Monday, August 24, 2009 5:48 PM
You can use Code Access Security to Demand a permission. It will throw an exception that you can handle if the user tries to run the program with the wrong security level. You may need to write a method to run this specific section with elevated priviledges, but I'm getting ahead of myself. First we need to establish a working baseline.
Can you/have you tried running the program on your own machine, as administrator, with unrestricted domain policy?
おろ?
Tuesday, August 25, 2009 3:22 AM
Another thing to note is the serial# is stored in the BIOS and often on a programmable EEPROM chip. If u ever had a bad flash, remanufactured board, ran a program to update flash values to user specified values, or simply never had the serial# programmed for any reason you can get empty string for that machine.
おろ?
Tuesday, August 25, 2009 8:34 AM
Hello CodesCrawler,
Your codes look good and have run correctly in my side too! It returns the SN string as,
"..CN1374078N001G."
So the issue should be at machine side instead of C# codes side. Have you tried to find another machine to test with the same codes? And as far as I know, we can use a tool named EVEREST to observe a machine's hardware information including motherboard ID. You can download a trial version to see if the tool can find the machine's motherboard id.
Ji Zhou
MSDN Subscriber Support in Forum
If you have any feedback on our support, please contact msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Tuesday, August 25, 2009 9:23 AM
Hello,
Indirectly related to the topic I really recommand you to use the Microsoft WMI Code Creator tool, it's makes WMI programming, and debugging relatively easy.Eyal, Regards.
Friday, August 28, 2009 8:29 AM
Hello CodesCrawler,
What is the status of the issue in your side?
Ji Zhou
MSDN Subscriber Support in Forum
If you have any feedback on our support, please contact msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Monday, August 31, 2009 2:20 PM
Thanks everyone for your help. I haven't had a chance to re-test the codes on a different machine. I only tested the listed codes on my current machine and the result remains empty. I guess that my PC doesn't allow me to access MB ID.
I'll continue to use my codes (or Smacky's codes). If any machine returns empty string, that machine will be considered to have ID = 0. The issue is not very important because MB ID is only a part of a composite key.
Tuesday, November 15, 2016 10:30 AM
Not sure that ManageObject can get to the info 100% of the time. Your method works on my machine. Here's another way to try it:
public static string GetMotherBoardID() { string mbInfo = String.Empty; ManagementScope scope = new ManagementScope("\\\\" + Environment.MachineName + "\\root\\cimv2"); scope.Connect(); ManagementObject wmiClass = new ManagementObject(scope, new ManagementPath("Win32_BaseBoard.Tag=\"Base Board\""), new ObjectGetOptions()); foreach (PropertyData propData in wmiClass.Properties) { if (propData.Name == "SerialNumber") mbInfo = String.Format("{0,-25}{1}", propData.Name, Convert.ToString(propData.Value)); } return mbInfo; }Also, do you have any domain policy restrictions that may prevent you from getting this info? おろ?
Hi.
Does it base on **OnDemand **request?
I mean, what if I make GHOST Image of my whole OS and install it on another System? Will it return new*SerialNumber *or the same old one?
Regards,
Pritam Upadhyay.
Sunday, August 26, 2018 8:08 PM
your code is running but get part of the serial no
not all of it