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
Answers (1)
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