Click to See Complete Forum and Search --> : Reading MAC w/ VBS


Astrotolus
07-04-2005, 10:09 PM
I'm writing a vb script to extract the MAC from a workstation and write it as the computer name. I have a working solution now but it's a bit clumsy.

I have a batch file that calls "getmac /fo table /nh >> c:\mac.txt", then calls a vb script file which reads the MAC address from the file, writes the name then restarts the computer.

I'm sure there must be an easier way to get the MAC, avoid using the text file and have a complete solution with just vbs. I haven't been able to find the MAC in the registry, but I know it's possible (though I don't know how exactly) to read the MAC using Windows Management Instrumentation (WMI).

So, I was hoping someone could help we out with some vbs code to write the MAC into a variable. From there I should be able to get it going. I'll give the rest of the script, small as it is, to anyone who can help me out.

Thanks.

rock
07-05-2005, 08:21 AM
I found a Java program that will do it, but through parsing ifconfig (Unix) or ipconfig (Windows) output. It's a little cleaner than using an intermediate text file. Link: http://forum.java.sun.com/thread.jspa?threadID=245711&tstart=225

Googling for this kind of thing is touch because of the 'mac' phrase!

Astrotolus
07-05-2005, 09:39 AM
Thanks Rock. I'd still like to keep everything in one vbs though. That windows sections of code will be longer than the whole rest of my script. Any ideas on how to do it with vbs?

rock
07-05-2005, 09:59 AM
Parsing the output of "ipconfig /all" would still seem to be the key. I don't know enough about vbs to know if you can capture that output into a string and then run through it programmatically.