[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Win32_NetworkAdapter Array ToString()???

Posted on 2006-05-12
8
Medium Priority
?
767 Views
Last Modified: 2008-01-09
I would like ONE long continuous string of ALL MAC Addresses instead of several individual ones provided by the following method.

ManagementObjectSearcher find = new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapter");
            foreach (ManagementObject mo in find.Get())
            {
                string NicMacAddr = (mo["MACAddress"].ToString());              
            }


0
Comment
Question by:kvnsdr
  • 4
  • 4
8 Comments
 
LVL 35

Accepted Solution

by:
mrichmon earned 1000 total points
ID: 16670996
ManagementObjectSearcher find = new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapter");
string NicMacAddr = "";
            foreach (ManagementObject mo in find.Get())
            {
                NicMacAddr += (NicMacAddr.Length == 0 ? "; " : "") + (mo["MACAddress"].ToString());
            }

This will make each one separated bya semi-colon and space, but all in the same string.  If you want a differnt separator then just modify that portion of the above.
0
 
LVL 1

Author Comment

by:kvnsdr
ID: 16678378
Can't get it to work. I was thinking about:

foreach (ManagementObject mo in find.Get())
            {
                string[] NicMacAddr = (mo["MACAddress"].ToString());
            }
0
 
LVL 35

Expert Comment

by:mrichmon
ID: 16683089
What is an error you are getting?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Author Comment

by:kvnsdr
ID: 16684242
"Object reference not set to the instance of an object."

 NicMacAddr += (NicMacAddr.Length == 0 ? "; " : "") + (mo["MACAddress"].ToString());
0
 
LVL 35

Expert Comment

by:mrichmon
ID: 16684332
Did you include the first line above the loop to define the variable as a string?
0
 
LVL 1

Author Comment

by:kvnsdr
ID: 16684534
oh yes, just didn't include in comment.
0
 
LVL 35

Expert Comment

by:mrichmon
ID: 16684586
If the code you provided initially was working, then the changes I showed would give the results you want.  But it is possible tha tthe error is from that code...
0
 
LVL 1

Author Comment

by:kvnsdr
ID: 16685000
I find it interesting that my code gives the following results.

Notice the duplicate MACs and the blanks that are probably throwing an error with your code.

I only have 2 NICs in the test machine........

I've been using a BREAK; after my code to prevent errors........

MAC Address... D1:FD:04:5E:2D:A4
MAC Address...
MAC Address...
MAC Address... 40:50:44:51:20:20
MAC Address... 23:50:6E:55:20:20
MAC Address...
MAC Address...
MAC Address... 20:02:20:51:42:23
MAC Address... 00:0A:D1:7C:E6:CA
MAC Address... 00:0A:D1:7C:E6:CA
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question