I have come to you today with a problematic snippet of code I have.
Set mac = CreateObject("WScript.Shell").Exec("cmd.exe /C ipconfig /all")
Do While mac.Status = 0
WScript.Sleep 100
Loop
MsgBox "Your MAC address is " & vbNewLine & Left(Right(mac.StdOut.ReadAll, 775),756), vbExclamation, "Physical Address"
Set mac = Nothing
My goal is to find the physical address of the computer and return it with a msgbox;
However, upon running this program I am met with 2 things:
- The CMD program didn't close, even when I added a /C to the command.
- Upon closer inspection, I found (with the Len() function) that in CMD ipconfig /all counted over 6000 characters, but with this program, it stated that the command returned only 4000 characters.
I know for a fact that there is something wrong with Set mac = CreateObject("WScript.Shell").Exec("cmd.exe /C ipconfig /all")
but I don't know even after checking other answers and such.
I would suggest, that you forget about running ipconfig.exe and then trying to parse all of its returned text to retrieve the
MACAddress
, and instead use WMIExample: