Hello Daniweb,
I am writing an App that uses two buttons, two radiobuttons, and a textbox to use the Windows shell command to print the "getmac" command to a text file: i.e.
"getmac /v >> whatever.txt"
I want to save the "wireless" MAC addresses to a text file from a bunch of computers with this app.
i.e. output:
COMPUTER: name-PC
_________________________________________
WIRELESS MAC: 00-22-03-FF-EE-DD
_________________________________________
COMPUTER: nameTwoXP-PC
_________________________________________
WIRELESS MAC: 00-00-FF-32-55-33
and so on by the ">>
" symbol in the shell command "getmac \v >> text.txt
" and true at the end of the writeAllText (...., true)
appends each next PC on to the list.
This app can be great for computer WIFI inventories.
What I need is some code to use the second button to filter out the lines with "wireless" to the end of the that line (which includes the WIFI MAC Address) and then delete everything else until the delimiter "COMPUTER: ".
I have played with the code and below is what I have used so far to get the WIFI MACs but I do not think the output is clean enough.
Any hints?
My code is below:
______________________________________________________________________
Imports System.Text.RegularExpressions
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If RadioButton2.Checked = True Then
Dim name As String = My.Computer.Name
Dim path As String = My.Computer.FileSystem.CurrentDirectory & "\MACLIST.txt"
My.Computer.FileSystem.WriteAllText(path, "______________________________________" & vbNewLine & vbNewLine, True)
My.Computer.FileSystem.WriteAllText(path, "COMPUTER: " & name & vbNewLine, True)
' My.Computer.FileSystem.CurrentDirectory &
Shell("cmd.exe /c getmac /v >> MACLIST.txt", AppWinStyle.MaximizedFocus)
My.Computer.FileSystem.WriteAllText(path, "______________________________________" & vbNewLine & vbNewLine, True)
ElseIf RadioButton1.Checked = True Then
TextBox1.Enabled = True
If String.IsNullOrEmpty(TextBox1.Text.Trim()) Or TextBox1.Text.Contains(".") Then
MsgBox("Please enter a valid output file name")
Else
Dim name1 As String = My.Computer.Name
Dim path1 As String = My.Computer.FileSystem.CurrentDirectory & "\" & TextBox1.Text.Trim & ".txt"
My.Computer.FileSystem.WriteAllText(path1, "______________________________________" & vbNewLine & vbNewLine, True)
My.Computer.FileSystem.WriteAllText(path1, "COMPUTER: " & name1 & vbNewLine, True)
' My.Computer.FileSystem.CurrentDirectory &
Shell("cmd.exe /c getmac /v >> " & TextBox1.Text.Trim & ".txt", AppWinStyle.MaximizedFocus)
My.Computer.FileSystem.WriteAllText(path1, "______________________________________" & vbNewLine & vbNewLine, True)
End If
End If
TextBox1.Enabled = True
Button2.Select()
End Sub
Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
If RadioButton2.Checked = True Then
TextBox1.Enabled = False
ElseIf RadioButton1.Checked = True Then
TextBox1.Enabled = True
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If RadioButton1.Checked = True Then
'"([0-9a-fA-F][0-9a-fA-F]-){5}([0-9a-fA-F][0-9a-fA-F])"
Dim fso, inputFile, outputFile
Dim str As String
fso = CreateObject("Scripting.FileSystemObject")
'1 means for reading
inputFile = fso.OpenTextFile(TextBox1.Text.Trim & ".txt", 1)
str = inputFile.ReadAll
'modify this string, replace required characters
str = Replace(str, "Wireless", "_______________________________" & vbNewLine & "******WIRELESS Next Line******" & vbNewLine & "_______________________________" & vbNewLine)
str = Replace(str, "Connection Name Network Adapter Physical Address Transport Name ", "")
str = Replace(str, "=============== =============== ===================", "")
str = Replace(str, "==========================================================", "")
'write back
outputFile = fso.CreateTextFile(TextBox1.Text.Trim & ".txt", True)
outputFile.Write(str)
ElseIf RadioButton2.Checked = True Then
Dim a As String
Dim fso, inputFile, outputFile
Dim str As String
fso = CreateObject("Scripting.FileSystemObject")
'1 means for reading
inputFile = fso.OpenTextFile("MACLIST.txt", 1)
str = inputFile.ReadAll
'modify this string, replace required characters
str = Replace(str, "Wireless", "_______________________________" & vbNewLine & "******WIRELESS Next Line******" & vbNewLine & "_______________________________" & vbNewLine)
str = Replace(str, "Connection Name Network Adapter Physical Address Transport Name ", "")
str = Replace(str, "=============== =============== ===================", "")
str = Replace(str, "==========================================================", "")
'str = Replace(str, , "")
'write back
outputFile = fso.CreateTextFile("MACLIST.txt", True)
outputFile.Write(str)
'System.Diagnostics.Process.Start("MACLIST.txt")
End If
End Sub
End Class
Thanks in advance,
m1234ike