|
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.
|
|
|
|
|
i know that.i mean i have a font file(.ttf),my program first load this font to memcry.
but i don't know how to let the label to display text with the font.
i know one waw can get it.for exam:
System.Drawing.Text.PrivateFontCollection pfc = new System.Drawing.Text.PrivateFontCollection();
pfc.AddFontFile("d:\\tmp\\Ni7seg.ttf");
Font myFont = new Font(pfc.Families[0], 80f, FontStyle.Regular, GraphicsUnit.Point, 0);
but my program is running in wince that don't support "System.Drawing.Text.PrivateFontCollection".
so who know how to implement this through winapi.
|
|
|
|
|
If you use Reflector, you can easily dig out the internals of how PrivateFontCollection works, and wrap up your own implementation using just the bits you need. (Here's a hint - I just took a quick peek using Reflector and found that adding a new font relies on:
[DllImport("gdiplus.dll", CharSet=CharSet.Unicode, SetLastError=true, ExactSpelling=true)]
internal static extern int GdipPrivateAddMemoryFont(HandleRef fontCollection, HandleRef memory, int length);
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Not sure. See if this[^] helps. Looks somewhat similar to what you are doing.
|
|
|
|
|
My program creates a registry key under HKEY_CURRENT_USER\Software.
There is no problem creating the key or creating values underneath it.
However the framework throws an UnauthorizedAccessException when I try to delete the key using the "DeleteSubKey" method of the RegistryKey class.
The program is running as the same user that created the key.
This is on Vista SP2.
What could I be missing? I thought that a user has total access to keys underneath HKEY_CURRENT_USER?
|
|
|
|
|
Never mind!
I found out that I'm supposed to open the key with delete-access to begin with.
Thanks for reading my post.
|
|
|
|
|
hi.
I need help in this.
I have a textbox and two radiobutton.
For example, If the data in the textbox is yes, I want the yes button to be selected. If the data in the textbox is no, the no button is selected.
so far the code i have is this,
if (query returns true)
{
VMradioButton.Checked = true;
TnRradioButton.Checked = false;
}
else{
VMradioButton.Checked = false;
TnRradioButton.Checked = true;
}
please, need help. thanks
|
|
|
|