|
When I Put The Namespace
using System.Management;
The ManagementScope Does Not Work
|
|
|
|
|
|
The type or namespace 'ManagementScope' could not be found...
|
|
|
|
|
Add a reference to System.Management in your application.
|
|
|
|
|
|
Like this[^].
System.Management will be in the first tab itself.
|
|
|
|
|
There IS An Erorr
ManagementScope theScope = new ManagementScope("\\\\computerName\\root\\cimv2");
StringBuilder theQueryBuilder = new StringBuilder();
theQueryBuilder.Append("SELECT MACAddress FROM Win32_NetworkAdapter");
ObjectQuery theQuery = new ObjectQuery(theQueryBuilder.ToString());
ManagementObjectSearcher theSearcher = new ManagementObjectSearcher(theScope, theQuery);
ManagementObjectCollection theCollectionOfResults = theSearcher.Get();
foreach (ManagementObject theCurrentObject in theCollectionOfResults)
{
string macAdd = "MAC Address: " + theCurrentObject["MACAddress"].ToString();<-----------Erorr(Object Reference not set to an ...)
MessageBox.Show(macAdd);
}
What can I Do?
|
|
|
|
|
The key here is debugging. It is a skill you must learn if you want to learn programming.
First thing to do is set a breakpoint on any of the lines above the foreach(..) . Then start the programming in debug mode, I use F5, but you can do it from the menu if you prefer.
Then when the code stops at your breakpoint, begin examining the object's in scope paying attention to see if any are null. Im guessing it could be that theCollectionOfResults is null based on the location of the error, but you should see for yourself.
When you know what is null, you can work backwards to see which specific line of code is not behaving as you expect. It may be that you dont have permissions to read the MACAddress of the specified computer, it may be that that computer is unable to give you a MACAddress (you used to need a network adapter to have a MACAddress - this might not be true now).
I hope that helps.
good day.
|
|
|
|
|
sanforjackass wrote: What can I Do?
You really seem to be out of your depth with this problem, you are asking questions about the most basic of .NET programming operations (how to add a reference, for example) so I would suggest that what you can do is to get a beginners book on C# and .NET and work through it carefully. There are several free ones on the web some for those totally new to programming and some for those transferring from other languages. A forum like this is not the place to be spoon-fed, solutions.
To answer your most recent problem. The error is being caused because there is either no such thing as theCurrentObject["MACAddress"] i.e. no such member, or, more likely, the content of theCurrentObject["MACAddress"] is null. So test for null before trying to access it and act on the result of that test.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
I Want My Own Mac Address How Can I Get It?
|
|
|
|
|
J4amieC has told you how to find out what is going wrong in your code.
Follow his advice.
If you are unable to resolve the problem by doing that, you might try Googling for getting mac address for computer. I did and got loads of hits. If you want to cut down on the number, refine the search, try getting mac address for computer c#.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
sanforjackass wrote: I Want My Own Mac Address How Can I Get It?
People aren't generally assigned their own MAC address, so I think your only recourse is to purchase a network card. Each one comes with a MAC address.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Dude, you're a complete retard, aren't you...
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
From the other stuff you posted, I'm surprised that you understand the concept of a namespace.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Which MAC address?
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
|
Which network adapter?
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Hi,
I have a doubt in datagridview. I'm retrieving data from sql to datagridview. Now my problem is that i have to edit the data and store the new data into the sql again.plz help......
Thanks in advance..
|
|
|
|
|
This[^] is how it can be done.
|
|
|
|
|
Thanks, but this code is not working i have already implemented this code. can u send me another code for saving the updated values into the database.
Thanks in advance........
|
|
|
|
|
Hi,
I have 4 different cameras located in my home.
These 4 cameras are connected to 4 channel DVR.
DVR store recorded video stream data in raw format on one attached hard disk drive.
I assign static IP address to this DVR, and DVR throws video streams on this IP address and 80 port.
Are there any ways to read video streams from this IP address and 80 port of DVR.
Regards,
Kunal.
|
|
|
|
|
My guess would be "yes".
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Request you to please give me some method description of how i can do this in C# or C++/MFC.
|
|
|
|
|
first:i use two functions to install a new font int the following.
AddFontResource("d:\\tmp\\Ni7seg.ttf");
SendMessage((IntPtr)0xFFFF, WindowsMessages.WM_FONTCHANGE, IntPtr.Zero, IntPtr.Zero);
second:i don't konw how to use the new font.how to set the label's text with the new font?who can give me a example?very thanks
|
|
|
|
|
A label has a font property. You can use that to set the font for the Label text.
|
|
|
|