Reading MAC w/ VBS

Sharky Forums


Results 1 to 4 of 4

Thread: Reading MAC w/ VBS

  1. #1
    Catfish Astrotolus's Avatar
    Join Date
    Jun 2001
    Posts
    226

    Reading MAC w/ VBS

    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.

  2. #2
    NullPointerException rock's Avatar
    Join Date
    Sep 2000
    Location
    York, PA
    Posts
    6,203
    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.jsp...711&tstart=225

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

    Open Source is free like a puppy is free.

    It's only when you look at an ant through a magnifying glass on a sunny day that you realise how often they burst into flames.

    Understanding Evolution

  3. #3
    Catfish Astrotolus's Avatar
    Join Date
    Jun 2001
    Posts
    226
    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?

  4. #4
    NullPointerException rock's Avatar
    Join Date
    Sep 2000
    Location
    York, PA
    Posts
    6,203
    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.

    Open Source is free like a puppy is free.

    It's only when you look at an ant through a magnifying glass on a sunny day that you realise how often they burst into flames.

    Understanding Evolution

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •