-1
我正在製作一個應用程序,顯示計算機上所有WLAN配置文件的關鍵。VB.net路徑中的非法字符
'' GET PROFILES
Dim temp_direct As String = My.Computer.FileSystem.SpecialDirectories.Temp
Dim cmd As String = "Netsh WLAN show profiles > " & temp_direct & "\profiles.txt"
Shell("cmd.exe /c " + cmd, AppWinStyle.Hide, True)
'' SHOW PROFILES
Dim texto As String = File.ReadAllText(temp_direct & "\profiles.txt").Replace(" ", "")
Dim pattern As String = "AllUserProfile:(.*)"
Dim matches As MatchCollection = Regex.Matches(texto, pattern)
For Each m As Match In matches
For Each c As Capture In m.Captures
RichTextBox1.AppendText("SSID: " & m.Groups(1).Value)
'' SAVE PROFILE WITH CLEAR KEY
Dim cmd_info As String = "Netsh WLAN show profiles " & m.Groups(1).Value & " key=clear" & " > " & temp_direct & "\" & m.Groups(1).Value & ".txt"
Shell("cmd.exe /c " + cmd_info, AppWinStyle.Hide, True)
'' SHOW KEY ON RICHTEXTBOX
Dim ficheiro As String = m.Groups(1).Value & ".txt"
Dim pass_file As String = File.ReadAllText(Path.Combine(temp_direct, ficheiro)).Replace(" ", "")
Dim pattern_pass As String = "KeyContent:(.*)"
Dim match_key As Match = Regex.Match(pass_file, pattern_pass)
If match_key.Success Then
RichTextBox1.AppendText("Key: " & match_key.Groups(1).Value)
End If
Next
Next
我得到一個異常(路徑中具有非法字符):
Dim pass_file As String = File.ReadAllText(Path.Combine(temp_direct, ficheiro)).Replace(" ", "")
所以我認爲這是問題的因爲某些原因沒有關係」的「m.Groups(1).value的」不會被認作是一個字符串?因爲如果我使用
Path.Combine(temp_direct, "NAME.txt")
這樣工作,我試圖改變比賽「的ToString」,不與分離等文件類型「價值」,但它不工作。我也試圖在論壇上搜索,但沒有運氣。
http://stackoverflow.com/a/23182807/1383168 – Slai
@Slai非常感謝你!它正在工作! –
也有更好的方法來讀取命令輸出http://stackoverflow.com/questions/11504981/reading-and-writing-to-a-command-prompt-console-using-vb-net – Slai