kneze Posted April 12, 2017 Share Posted April 12, 2017 (edited) Hi i try to read Wlan Profiles from local Computer. First Step Command Prompt: netsh wlan show profiles >> C:\temp\test\wlan.txt. Second Step (here's a sample script to find a solution for my problem. Script read each line of wlan.txt and Display Name of Wireless Connection which i have set up in the past. If i edit wlan.txt to wlan - sample.txt script works. wlan.txt containsline without : so i get error message. How can i read only lines beginning with All User Profile so i can use original file wlan.txt which i crate in the command prompt with: netsh wlan show profiles >> C:\temp\test\wlan.txt ? Thanks for any suggestions. Kneze $Form1 = GUICreate("Form1", 374, 268, 892, 512) $Button1 = GUICtrlCreateButton("button", 145, 35, 75, 25) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $file = "C:\temp\test\wlan.txt" FileOpen($file, 0) For $i = 1 to _FileCountLines($file) $line = FileReadLine($file, $i) $after = StringSplit($line, ":")[2] MsgBox(262144, "Result", $after, 0) Next FileClose($file) EndSwitch WEnd wlan - sample.txt wlan.txt Edited April 12, 2017 by kneze Link to comment Share on other sites More sharing options...
Floops Posted April 12, 2017 Share Posted April 12, 2017 (edited) Can you try this and report back please? $line = FileReadLine($file, $i) If StringInStr($line, "All User Profile") Then $after = StringSplit($line, ":")[2] MsgBox(262144, "Result", $after, 0) EndIf Edited April 12, 2017 by Floops Link to comment Share on other sites More sharing options...
ViciousXUSMC Posted April 12, 2017 Share Posted April 12, 2017 Could you post up an example of the .txt file? I imagine you can find a different way to parse the line, such as the line break instead of the colon. Also you can get the results directly in code without writing to a file first unless you need/want the physical file for some reason. Link to comment Share on other sites More sharing options...
Floops Posted April 12, 2017 Share Posted April 12, 2017 @ViciousXUSMC He attached both text files to his original post Link to comment Share on other sites More sharing options...
ViciousXUSMC Posted April 12, 2017 Share Posted April 12, 2017 (edited) Good catch, I was looking for it posted in the message body. This is just one way of doing it: #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <File.au3> #Include <Array.au3> $Form1 = GUICreate("Form1", 374, 268, 892, 512) $Button1 = GUICtrlCreateButton("button", 145, 35, 75, 25) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 _ReadFile() EndSwitch WEnd Func _ReadFile() $sFile = FileRead(@ScriptDir & "\wlan.txt") $aResults = StringRegExp($sFile, "(?i)all user profile\s+:\s*(.*)", 3) _ArrayDisplay($aResults) EndFunc Edited April 12, 2017 by ViciousXUSMC Link to comment Share on other sites More sharing options...
mikell Posted April 12, 2017 Share Posted April 12, 2017 If each profile includes "@" then this other way could work #Include <Array.au3> $aResults = StringRegExp(FileRead(@ScriptDir & "\wlan.txt"), '\S+@\S+', 3) _ArrayDisplay($aResults) ss26 1 Link to comment Share on other sites More sharing options...
kneze Posted April 12, 2017 Author Share Posted April 12, 2017 thanks for your support. Its great. kneze Link to comment Share on other sites More sharing options...
ViciousXUSMC Posted April 13, 2017 Share Posted April 13, 2017 16 hours ago, mikell said: If each profile includes "@" then this other way could work #Include <Array.au3> $aResults = StringRegExp(FileRead(@ScriptDir & "\wlan.txt"), '\S+@\S+', 3) _ArrayDisplay($aResults) It would capture the wireless profile but not meet the criteria must match "All User Profile" it could be user specific profiles it matches also. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now