I modified and example of a VB script to pull the computer name and the MAC address, but it outputs to a MsgBox and I want it to output to a text file...I am not very good at changing output methods within VB scripting, any thoughts?

Here is the coding I have:

Set WshNetwork = WScript.CreateObject("WScript.Network")
sComputer = "Computer Name: " & WshNetwork.ComputerName
wmiQuery = "Select * from Win32_NetworkAdapterConfiguration " & "Where IPEnabled = 'True'"
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery(wmiQuery)
 
For Each objItem In colItems
 For Each IPAddr In objItem.IPAddress
  If IPAddr <> "0.0.0.0" Then
   sMacAddress = "MAC Address: " & objItem.MACAddress
  End If
 Next
Next
MsgBox sComputer & vbLf & vbLf & sMacAddress

Answer Summary:
Cancel
0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Answers

2

Set WshNetwork = CreateObject("WScript.Network")
sComputer = "Computer Name: " & WshNetwork.ComputerName
wmiQuery = "Select * from Win32_NetworkAdapterConfiguration " & "Where IPEnabled = 'True'"
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery(wmiQuery)
 
For Each objItem In colItems
 For Each IPAddr In objItem.IPAddress
  If IPAddr <> "0.0.0.0" Then
   sMacAddress = "MAC Address: " & objItem.MACAddress
  End If
 Next
Next

Set objShell = CreateObject ("WScript.Shell")
Set objFSO = CreateObject ("Scripting.FileSystemObject")
CurrentDir = objShell.CurrentDirectory
Set oFile = objFSO.CreateTextFile(CurrentDir & "\MyText.txt",1)

oFile.WriteLine sComputer
oFile.WriteLine sMacAddress


oFile.Close

Answered 09/05/2013 by: jagadeish
Red Belt

  • Thanks that works, and does what I need it to do, if I wanted it to save to like "C:\SOME_FOLDER\Output.txt" would I just use...

    'REMOVE THIS: CurrentDir = objShell.CurrentDirectory
    Set oFile = objFSO.CreateTextFile("C:\SOME_FOLDER\Output.txt", 1)
    • I decided to just test it out, and I got it working to save to a specified directory, thanks a lot I really appreicate it.
  • Next stop...Google!
    • Haha...Google is currently my life...UGH, except apprently multiple people have tried to figure out if send keys can accept user input and then return that as an output. No one seems to have a straight answer as far as variables and user input go with SendKeys....RIDICULIOUS HAHAHA
Please log in to comment
Answer this question or Comment on this question for clarity