/build/static/layout/Breadcrumb_cap_w.png

ComputerInformation VBS, MsgBox to saved Text File...

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


0 Comments   [ + ] Show comments

Answers (1)

Answer Summary:
Posted by: jagadeish 11 years ago
Red Belt
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


Comments:
  • 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) - 56kGhost 11 years ago
    • 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. - 56kGhost 11 years ago
  • Next stop...Google! - anonymous_9363 11 years ago
    • 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 - 56kGhost 11 years ago
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ