Jump to content

SmOke_N

Moderators
  • Posts

    16,280
  • Joined

  • Days Won

    17

Reputation Activity

  1. Like
    SmOke_N got a reaction from ioa747 in Ini+Ex Functions - exceed 32kb limit   
    Sometimes I see posts where people are complaining about the 32kb limit on IniReadSetion. I never did understand why you would have a section that was 32kb's...

    One of my string parsing functions reads and writes to an ini, well for the first time ever, the section was 34.x kbs and I couldn't understand for the longest time (about 10 trials of re-writing different things) why I wasn't getting all the values... Just bits and pieces it seemed. I never check for anything other than if IniReadSection is an array... But then I thought to look at the size... and their lay the problem.

    I wrote a really slow IniReadSection for someone else 2 or so months ago that had this problem, and to be honest, it was 2000 times slower than the current released one that Valik wrote...

    This didn't suite my needs either, as every second counts ... So I wrote another one, This one isn't near as fast as Valiks for obvious reasons, but it did the trick 20x's faster than the last one I wrote.

    Hope it helps someone...

    Update: - 2011/05/18 - SmOke_N
    Changed: _IniReadSectionEx() - Changed all existing functions; hopefully more proficient; thanks llewxam

    Old Code:




    ; New code with changes, be sure to test if you have doubts. I only moderately tested.
    ; The IniRead* functions now accept a passed string ( like from a FileRead() or ClipPut() etc... )

    ; change added - SmOke_N - 2011/05/18 Func _IniDeleteEx($s_file, $s_section, $s_key = "") If Not FileExists($s_file) Then Return SetError(-1, 0, 0) Local $i_size = FileGetSize($s_file) Local $i_delete = 0 If $i_size < 31 Then $i_delete = IniDelete($s_file, $s_section, $s_key) Return SetError(@error, 0, $i_delete) EndIf ; is file read only If StringInStr(FileGetAttrib($s_file), "R") Then Return SetError(-2, 0, 0) EndIf Local $s_fread = FileRead($s_file) ; find out if section exist, if so get data Local $s_secpatt = "(?si)(?:^|\v)(\h*\[\h*\Q" $s_secpatt &= $s_section $s_secpatt &= "\E\h*\].*?)(?:\z|\v\v?\[)" Local $a_data = StringRegExp($s_fread, $s_secpatt, 1) Local $f_dataexists = Not @error If Not $f_dataexists Then Return 1 Local $h_open, $i_write = 0 If $s_key = "" Then If $s_fread = $a_data[0] Then $h_open = FileOpen($s_file, 2) If $h_open = -1 Then Return SetError(-3, 0, 0) FileClose($h_open) Return 1 EndIf $s_fread = StringReplace($s_fread, $a_data[0], "", 1, 1) $h_open = FileOpen($s_file, 2) If $h_open = -1 Then Return SetError(-3, 0, 0) $i_write = FileWrite($h_open, $s_fread) FileClose($h_open) If Not $i_write Then Return SetError(-4, 0, 0) Return 1 EndIf ; since we stop at cr/lf then lets just split Local $a_lines If StringInStr($a_data[0], @CRLF, 1, 1) Then $a_lines = StringSplit(StringStripCR($a_data[0]), @LF) ElseIf StringInStr($a_data[0], @LF, 1, 1) Then $a_lines = StringSplit($a_data[0], @LF) Else $a_lines = StringSplit($a_data[0], @CR) EndIf Local $a_key, $f_found = False, $s_write Local $s_keypatt = "\h*(?!;|#)(.*?)\h*=" For $iline = 1 To $a_lines[0] If $a_lines[$iline] = "" Then ContinueLoop $a_key = StringRegExp($a_lines[$iline], $s_keypatt, 1) If @error Or $s_key <> $a_key[0] Then $s_write &= $a_lines[$iline] & @CRLF ContinueLoop EndIf $f_found = True Next If Not $f_found Then Return 1 $s_fread = StringReplace($s_fread, $a_data[0], $s_write) Local $h_open = FileOpen($s_file, 2) $i_write = FileWrite($h_open, $s_fread) FileClose($h_open) Return $i_write EndFunc ; change added - SmOke_N - 2011/05/18 Func _IniWriteEx($s_file, $s_section, $s_key, $s_value) If Not $s_file Then Return SetError(-1, 0, 0) Local $f_exists = FileExists($s_file) If Not $f_exists Then FileClose(FileOpen($s_file, 2)) EndIf Local $i_write = 0 Local $i_size = FileGetSize($s_file) / 1024 ; if the file is smaller than 32kb, no need for regex If $i_size <= 31 Then $i_write = IniWrite($s_file, $s_section, $s_key, $s_value) Return SetError(@error, 0, $i_write) EndIf ; is file read only If $f_exists Then If StringInStr(FileGetAttrib($s_file), "R") Then Return SetError(-2, 0, 0) EndIf EndIf Local $s_fread = FileRead($s_file) Local $s_write = "" ; find out if section exist, if so get data Local $s_secpatt = "(?si)(?:^|\v)(\h*\[\h*\Q" $s_secpatt &= $s_section $s_secpatt &= "\E\h*\].*?)(?:\z|\v\v?\[)" Local $a_data = StringRegExp($s_fread, $s_secpatt, 1) Local $f_dataexists = Not @error Local $s_write = "" ; if section doesn't exist; append If Not $f_dataexists Then If $s_fread Then If StringRight($s_fread, 2) <> @CRLF Then $s_write &= @CRLF EndIf EndIf $s_write &= "[" & $s_section & "]" & @CRLF $s_write &= $s_key & "=" & $s_value & @CRLF Return FileWrite($s_file, $s_write) EndIf ; since we stop at cr/lf then lets just split Local $a_lines If StringInStr($a_data[0], @CRLF, 1, 1) Then $a_lines = StringSplit(StringStripCR($a_data[0]), @LF) ElseIf StringInStr($a_data[0], @LF, 1, 1) Then $a_lines = StringSplit($a_data[0], @LF) Else $a_lines = StringSplit($a_data[0], @CR) EndIf Local $a_key, $f_changed = False Local $s_keypatt = "\h*(?!;|#)(.*?)\h*=" For $iline = 1 To $a_lines[0] If $a_lines[$iline] = "" Then ContinueLoop $a_key = StringRegExp($a_lines[$iline], $s_keypatt, 1) If @error Or $s_key <> $a_key[0] Then $s_write &= $a_lines[$iline] & @CRLF ContinueLoop EndIf $f_changed = True $s_write &= $s_key & "=" & $s_value & @CRLF Next If Not $f_changed Then If StringRight($s_fread, 2) <> @CRLF Then $s_write &= @CRLF EndIf $s_write &= $s_key & "=" & $s_value & @CRLF EndIf $s_fread = StringReplace($s_fread, $a_data[0], $s_write) Local $h_open = FileOpen($s_file, 2) $i_write = FileWrite($h_open, $s_fread) FileClose($h_open) Return $i_write EndFunc ; change added - SmOke_N - 2011/05/18 Func _IniReadSectionNamesEx($v_file) If Not $v_file Then Return SetError(-1, 0, 0) Local $f_exists = FileExists($v_file) Local $i_size, $a_secs If $f_exists Then $i_size = FileGetSize($v_file) / 1024 ; if the file is smaller than 32kb, no need for regex If $i_size <= 31 Then $a_secs = IniReadSectionNames($v_file) If @error Then Return SetError(@error, 0, 0) If Not IsArray($a_secs) Then Return SetError(-2, 0, 0) Return $a_secs EndIf EndIf Local $s_fread If Not $f_exists Then ; string of data was passed $s_fread = $v_file Else $s_fread = FileRead($v_file) EndIf Local $s_secpatt = "(?m)(?:^|\v)\h*\[\h*(.*?)\h*\]" Local $a_secsre = StringRegExp($s_fread, $s_secpatt, 3) If @error Then Return SetError(-3, 0, 0) Local $i_ub = UBound($a_secsre) Local $a_secret[$i_ub + 1] = [$i_ub] For $isec = 0 To $i_ub - 1 $a_secret[$isec + 1] = $a_secsre[$isec] Next Return $a_secret EndFunc ; change added - SmOke_N - 2011/05/17 Func _IniReadSectionEx($v_file, $s_section) If Not $v_file Then Return SetError(-1, 0, 0) Local $f_exists = FileExists($v_file) Local $i_size, $a_secread If $f_exists Then $i_size = FileGetSize($v_file) / 1024 ; if the file is smaller than 32kb, no need for regex If $i_size <= 31 Then $a_secread = IniReadSection($v_file, $s_section) If @error Then Return SetError(@error, 0, 0) If Not IsArray($a_secread) Then Return SetError(-2, 0, 0) Return $a_secread EndIf EndIf Local $s_fread If Not $f_exists Then ; string of data was passed $s_fread = $v_file Else $s_fread = FileRead($v_file) EndIf ; data between sections or till end of file Local $s_datapatt = "(?is)(?:^|\v)(?!;|#)\h*\[\h*\Q" $s_datapatt &= $s_section $s_datapatt &= "\E\h*\]\h*\v+(.*?)(?:\z|\v\h*\[)" Local $a_data = StringRegExp($s_fread, $s_datapatt, 1) If @error Then Return SetError(-3, 0, 0) ; sanity check for inf people If Not StringInStr($a_data[0], "=", 1, 1) Then Return SetError(-4, 0, 0) EndIf ; since we stop at cr/lf then lets just split Local $a_lines If StringInStr($a_data[0], @CRLF, 1, 1) Then $a_lines = StringSplit(StringStripCR($a_data[0]), @LF) ElseIf StringInStr($a_data[0], @LF, 1, 1) Then $a_lines = StringSplit($a_data[0], @LF) Else $a_lines = StringSplit($a_data[0], @CR) EndIf ; prevent capturing commented keys Local $a_key, $a_value Local $s_keypatt = "\h*(?!;|#)(.*?)\h*=" Local $s_valpatt = "\h*=\h*(.*)" Local $a_secs[$a_lines[0] + 1][2], $i_add = 0 For $iline = 1 To $a_lines[0] $a_key = StringRegExp($a_lines[$iline], $s_keypatt, 1) If @error Then ContinueLoop $s_valpatt = "\h*=\h*(.*)" $a_value = StringRegExp($a_lines[$iline], $s_valpatt, 1) If @error Then ContinueLoop If StringLeft($a_key[0], 1) = '"' And StringRight($a_key[0], 1) = '"' Then $a_key[0] = StringTrimLeft(StringTrimRight($a_key[0], 1), 1) EndIf If StringLeft($a_value[0], 1) = '"' And StringRight($a_value[0], 1) = '"' Then $a_value[0] = StringTrimLeft(StringTrimRight($a_value[0], 1), 1) EndIf $i_add += 1 $a_secs[$i_add][0] = $a_key[0] $a_secs[$i_add][1] = $a_value[0] Next If Not $i_add Then Return SetError(-5, 0, 0) ; cleanup return array ReDim $a_secs[$i_add + 1][2] $a_secs[0][0] = $i_add Return $a_secs EndFunc ; change added - SmOke_N - 2011/05/18 Func _IniReadEx($v_file, $s_section, $s_key, $v_default = -1) If Not $v_file Then Return SetError(-1, 0, 0) If $v_default = -1 Or $v_default = Default Then $v_default = "" EndIf Local $f_exists = FileExists($v_file) Local $i_size, $s_read If $f_exists Then $i_size = FileGetSize($v_file) / 1024 ; if the file is smaller than 32kb, no need for regex If $i_size <= 31 Then $s_read = IniRead($v_file, $s_section, $s_key, $v_default) Return $s_read EndIf EndIf Local $s_fread If Not $f_exists Then ; string of data was passed $s_fread = $v_file Else $s_fread = FileRead($v_file) EndIf ; data between sections or till end of file Local $s_datapatt = "(?is)(?:^|\v)(?!;|#)\h*\[\h*\Q" $s_datapatt &= $s_section $s_datapatt &= "\E\h*\]\h*\v+(.*?)(?:\z|\v\h*\[)" Local $a_data = StringRegExp($s_fread, $s_datapatt, 1) If @error Then Return SetError(-2, 0, 0) ; sanity check for inf people If Not StringInStr($a_data[0], "=", 1, 1) Then Return SetError(-3, 0, 0) EndIf ; since we stop at cr/lf then lets just split Local $a_lines If StringInStr($a_data[0], @CRLF, 1, 1) Then $a_lines = StringSplit(StringStripCR($a_data[0]), @LF) ElseIf StringInStr($a_data[0], @LF, 1, 1) Then $a_lines = StringSplit($a_data[0], @LF) Else $a_lines = StringSplit($a_data[0], @CR) EndIf ; prevent capturing commented keys Local $a_key, $a_value, $s_ret Local $s_keypatt = "\h*(?!;|#)(.*?)\h*=" Local $s_valpatt = "\h*=\h*(.*)" For $iline = 1 To $a_lines[0] $a_key = StringRegExp($a_lines[$iline], $s_keypatt, 1) If @error Then ContinueLoop If StringLeft($a_key[0], 1) = '"' And StringRight($a_key[0], 1) = '"' Then $a_key[0] = StringTrimLeft(StringTrimRight($a_key[0], 1), 1) EndIf If $a_key[0] <> $s_key Then ContinueLoop $s_valpatt = "\h*=\h*(.*)" $a_value = StringRegExp($a_lines[$iline], $s_valpatt, 1) If @error Then ContinueLoop If StringLeft($a_value[0], 1) = '"' And StringRight($a_value[0], 1) = '"' Then $a_value[0] = StringTrimLeft(StringTrimRight($a_value[0], 1), 1) EndIf $s_ret = $a_value[0] ExitLoop Next If Not $s_ret Then Return $v_default Return $s_ret EndFuncIf you're interested in Ini encryption, you might take a look at this thread:


    I might integrate these with the IniCrypt.au3 at some future time if I don't get bug feedback from the above.
  2. Like
    SmOke_N got a reaction from neogia in Stringregexp Guide   
    This is GREAT... neogia, thanks for sharing.
  3. Thanks
    SmOke_N got a reaction from WildByDesign in ComboBox - Change background and text color and or font   
    Not trying to re-invent the wheel here, but I found some examples that did A-L-O-T that I didn't think was necessary (like forcing owner-drawn), the sparse number of the web examples were failing miserably too.  It looked like @argumentum was taking the path I was on, his is much more feature rich ( 😅 ) ... Anyway, I was going to add a font option using this subclass method (Thanks to @LarsJ for his subclass method, saved me some time) but I am out of time and if I don't post this now, I will probably forget to post it later (Yep, age is getting there).
    @LarsJ - GUIRegisterMsg20 - 
    @argumentum ComboBox Set DROPDOWNLIST Colors/size UDF (Lots-O-Stuff) 
    Here's my short and sweet (I don't think I ever code anything short.. or sweet)
    Edit 2024-04-10:
    Added the font change functions, pay attention to the fact that there are 3 different hwnds, the control hwnd, the edit hwnd as well as the listbox hwnd for the combo box.  There are 4 functions, one changes all 3, the others change each of the other hwnds.
    Edit-2 2024-04-10:
    So I was going to use the forum members meticulous eyes to find issues, but I seemed to find a few that I didn't notice before myself.
    - Wrong array bounds in font au3 was fixed
    - Multi color (LB and Edit different colors) fixed (mistakenly used 1 brush ... oops) for color au3
    - Missing edit color logic fixed for color au3
     
     
     
     
    GUIComboBox.2024.04.10-002.zip
  4. Like
    SmOke_N got a reaction from Mobius in ClipBoard.au3 udf extras   
    After answering some clipboard questions in the help forum, I found myself writing a couple of helper funcs so I thought I'd share.
    I don't think I added any headers, I'm probably assuming (maybe to much?) that most will get it (yep, to lazy).
    Example code:
    #include "ClipBoardMisc.au3" #include <Array.au3> #cs Example 1 collect all the text/unicode/binary data in an array from clip #ce Global $gaArgs = _cbTest_GetAllData() _ArrayDisplay($gaArgs, Default, Default, Default, Default, _ "Format Type|Data TEXT|Data Unicode|Data Byte|Data ByteStr") Func _cbTest_GetAllData() Local $aClipFormats = _ClipBoard_GetCurrentFormatArray() If @error Then Return SetError(1, 0, Null) Local $aRet[UBound($aClipFormats)][5] ; [n][3] is memory address For $i = 0 To UBound($aClipFormats) - 1 ; Using all CBRT_ globals because I'm to lazy to go through all the CFSTR and do ; exhausting test functions to test what type of strings they are ; See: https://geekdude.io/static/ahk/Constants.W32.ini if you want to get a long list of CFSTR_ options $aRet[$i][0] = $aClipFormats[$i][2] $aRet[$i][1] = _ClipBoard_GetMemoryData($aClipFormats[$i][3], $CBRT_TEXT) $aRet[$i][2] = _ClipBoard_GetMemoryData($aClipFormats[$i][3], $CBRT_UNICODE) $aRet[$i][3] = _ClipBoard_GetMemoryData($aClipFormats[$i][3], $CBRT_BYTE) $aRet[$i][4] = _ClipBoard_GetMemoryData($aClipFormats[$i][3], $CBRT_BYTESTR) Next Return $aRet EndFunc  
    Example 2:  Get specific format id types array
    #include "ClipBoardMisc.au3" #include <Array.au3> ;~ #cs Example 2 ; Make sure you use "copy" on a file to test this ; Func: _ClipBoard_GetTypeArray($sType, $hOwner = 0) ; ; $sType: 1. String to be split by "|" separator char ; 2. Return type to be added similar as a struct ; example: $sType = "Text;str|FileNameW;wstr" ; Separates 2 types of arrays internally ; 1. Type array: [n] = "Text" ; [n] = "FileNameW" ; 2. Return type: [n] = "str" ; [n] = "wstr" ; Valid Format Return Strying types: ; "str" or "chr" ; "wstr" or "wchr" or "unicode" ; "byte" ; "bytestr" ; Return: Success: 2D array ; [n][0] = Found Type ; [n][1] = Found Value ; ; Note: It will not validate if the memory address is valid for your return type Global $ga_Test = _ClipBoard_GetTypeArray("filename;str|filenameW;wstr") If @error Then MsgBox(16, "Error", "Error: " & @error & " :: Extended: " & @extended) Else _ArrayDisplay($ga_Test) EndIf ;~ #ce ; updated zip
     
    ClipBoardMisc.zip
  5. Like
    SmOke_N got a reaction from Andreik in Problem with SELECT   
    That makes me giggle...
    Whatever the case, I know other mods are already fed up with his ignorantly posturized requests.  No matter what people suggest, if they don't write the code for them specifically, this OP is never satisfied to do the work or research.
    I know others are (including mods) are already at their limit.
    To the OP, start posting really worked on problems, start researching the suggestions given to you with examples on how those suggestions are not working for you, starting reading some manuals, manuals not only on coding, but maybe how to request help.
    I'm locking this topic, I know his last topic was locked as well.  Hopefully the OP gets the hint.
  6. Thanks
    SmOke_N got a reaction from SOLVE-SMART in Problem with SELECT   
    That makes me giggle...
    Whatever the case, I know other mods are already fed up with his ignorantly posturized requests.  No matter what people suggest, if they don't write the code for them specifically, this OP is never satisfied to do the work or research.
    I know others are (including mods) are already at their limit.
    To the OP, start posting really worked on problems, start researching the suggestions given to you with examples on how those suggestions are not working for you, starting reading some manuals, manuals not only on coding, but maybe how to request help.
    I'm locking this topic, I know his last topic was locked as well.  Hopefully the OP gets the hint.
  7. Like
    SmOke_N got a reaction from Musashi in Problem with SELECT   
    That makes me giggle...
    Whatever the case, I know other mods are already fed up with his ignorantly posturized requests.  No matter what people suggest, if they don't write the code for them specifically, this OP is never satisfied to do the work or research.
    I know others are (including mods) are already at their limit.
    To the OP, start posting really worked on problems, start researching the suggestions given to you with examples on how those suggestions are not working for you, starting reading some manuals, manuals not only on coding, but maybe how to request help.
    I'm locking this topic, I know his last topic was locked as well.  Hopefully the OP gets the hint.
  8. Haha
    SmOke_N reacted to Musashi in Problem with SELECT   
    A simple question : do you really want to learn, or is your avatar just a abbreviation for "other people have to solve my poorly defined questions" ?
  9. Like
    SmOke_N got a reaction from Danyfirex in ComboBox - Change background and text color and or font   
    Yeah, I was closing it out of SciTe when I noticed I had the wrong number of default elements in the return array... oops.
    You must have went to download it when I was uploading the fix... sorry
  10. Like
    SmOke_N got a reaction from Danyfirex in ComboBox - Change background and text color and or font   
    Not trying to re-invent the wheel here, but I found some examples that did A-L-O-T that I didn't think was necessary (like forcing owner-drawn), the sparse number of the web examples were failing miserably too.  It looked like @argumentum was taking the path I was on, his is much more feature rich ( 😅 ) ... Anyway, I was going to add a font option using this subclass method (Thanks to @LarsJ for his subclass method, saved me some time) but I am out of time and if I don't post this now, I will probably forget to post it later (Yep, age is getting there).
    @LarsJ - GUIRegisterMsg20 - 
    @argumentum ComboBox Set DROPDOWNLIST Colors/size UDF (Lots-O-Stuff) 
    Here's my short and sweet (I don't think I ever code anything short.. or sweet)
    Edit 2024-04-10:
    Added the font change functions, pay attention to the fact that there are 3 different hwnds, the control hwnd, the edit hwnd as well as the listbox hwnd for the combo box.  There are 4 functions, one changes all 3, the others change each of the other hwnds.
    Edit-2 2024-04-10:
    So I was going to use the forum members meticulous eyes to find issues, but I seemed to find a few that I didn't notice before myself.
    - Wrong array bounds in font au3 was fixed
    - Multi color (LB and Edit different colors) fixed (mistakenly used 1 brush ... oops) for color au3
    - Missing edit color logic fixed for color au3
     
     
     
     
    GUIComboBox.2024.04.10-002.zip
  11. Like
    SmOke_N got a reaction from ioa747 in ComboBox - Change background and text color and or font   
    Not trying to re-invent the wheel here, but I found some examples that did A-L-O-T that I didn't think was necessary (like forcing owner-drawn), the sparse number of the web examples were failing miserably too.  It looked like @argumentum was taking the path I was on, his is much more feature rich ( 😅 ) ... Anyway, I was going to add a font option using this subclass method (Thanks to @LarsJ for his subclass method, saved me some time) but I am out of time and if I don't post this now, I will probably forget to post it later (Yep, age is getting there).
    @LarsJ - GUIRegisterMsg20 - 
    @argumentum ComboBox Set DROPDOWNLIST Colors/size UDF (Lots-O-Stuff) 
    Here's my short and sweet (I don't think I ever code anything short.. or sweet)
    Edit 2024-04-10:
    Added the font change functions, pay attention to the fact that there are 3 different hwnds, the control hwnd, the edit hwnd as well as the listbox hwnd for the combo box.  There are 4 functions, one changes all 3, the others change each of the other hwnds.
    Edit-2 2024-04-10:
    So I was going to use the forum members meticulous eyes to find issues, but I seemed to find a few that I didn't notice before myself.
    - Wrong array bounds in font au3 was fixed
    - Multi color (LB and Edit different colors) fixed (mistakenly used 1 brush ... oops) for color au3
    - Missing edit color logic fixed for color au3
     
     
     
     
    GUIComboBox.2024.04.10-002.zip
  12. Like
    SmOke_N got a reaction from argumentum in ComboBox - Change background and text color and or font   
    Not trying to re-invent the wheel here, but I found some examples that did A-L-O-T that I didn't think was necessary (like forcing owner-drawn), the sparse number of the web examples were failing miserably too.  It looked like @argumentum was taking the path I was on, his is much more feature rich ( 😅 ) ... Anyway, I was going to add a font option using this subclass method (Thanks to @LarsJ for his subclass method, saved me some time) but I am out of time and if I don't post this now, I will probably forget to post it later (Yep, age is getting there).
    @LarsJ - GUIRegisterMsg20 - 
    @argumentum ComboBox Set DROPDOWNLIST Colors/size UDF (Lots-O-Stuff) 
    Here's my short and sweet (I don't think I ever code anything short.. or sweet)
    Edit 2024-04-10:
    Added the font change functions, pay attention to the fact that there are 3 different hwnds, the control hwnd, the edit hwnd as well as the listbox hwnd for the combo box.  There are 4 functions, one changes all 3, the others change each of the other hwnds.
    Edit-2 2024-04-10:
    So I was going to use the forum members meticulous eyes to find issues, but I seemed to find a few that I didn't notice before myself.
    - Wrong array bounds in font au3 was fixed
    - Multi color (LB and Edit different colors) fixed (mistakenly used 1 brush ... oops) for color au3
    - Missing edit color logic fixed for color au3
     
     
     
     
    GUIComboBox.2024.04.10-002.zip
  13. Like
    SmOke_N got a reaction from ioa747 in StringRegExpReplace with Upper/Lower option   
    Yep, you found an issue,
    If IsArray($aMUpUnique) Then should have been
    If IsArray($aMatchLower) Then Thanks for finding it, not sure how I did that before I posted ... doh!
  14. Like
    SmOke_N got a reaction from Musashi in StringRegExpReplace with Upper/Lower option   
    Yep, one of those moments where I forgot that \u or \l doesn't work with our PCRE engine 😞.
    So I *slap-sticked* some code together to achieve what I needed on the fly.
    This is truly ugly IMO, but if you're not doing a lot of string manipulation concatenations it's ok.  I know I wrote some pcre funcs in a dll back in the day for my personal use to be able to do some things like this, but of course I can't find it... So native it is.
    Anyway, I added this to my personal chars au3, thus the name you'll see.
    Please test and criticize away, like I said, it was a quick mod and it's A-L-O-T of regex this and regex that ... but maybe it's useful for someone.
    #include <StringConstants.au3> #include <Array.au3> ; #FUNCTION# ==================================================================================================================== ; Name ..........: _AutChars_RegExpReplaceEx ; Description ...: Allows StringRegExpReplace replace with pattern to do upper/lower ; Syntax ........: _AutChars_RegExpReplaceEx($sData, $sRegEx, $sReplace[, $iCount = 0]) ; Parameters ....: $sData - The string to check ; $sRegEx - The regular expression to compare. See StringRegExp for pattern definition characters. ; $sReplace - The text to replace the regular expression matching text with ; $iCount - Number of replacements. Default is 0 for global replacement ; Return values .: Success - an updated string based on regular expressions ; @extended = number of replacements performed ; Author ........: SmOke_N (Ron Nielsen.. Ron.SMACKThatApp@GMail.com) ; Modified ......: ; Related .......: See StringRegExpReplace() ; Remarks .......: Will only work with \u or \l such as \u$2 in replace with pattern ; In my opinion, this is a pretty abusive way to achieve this, might be fine for small jobs ; but the overhead would be immense ; Example .......: _AutChars_RegExpReplaceEx("abcdAbcefg", "abc", "\u$0") will return ABCdAbcefg ; =============================================================================================================================== Func _AutChars_RegExpReplaceEx($sData, $sRegEx, $sReplace, $iCount = 0) ; work in progress Local Const $iGlobalMatch = $STR_REGEXPARRAYGLOBALMATCH Local $sRet = "" Local Const $sMatchRE = "[\\$](?:u|l)[\$\\]{?\d+\}?" If Not StringRegExp($sReplace, $sMatchRE) Then $sRet = StringRegExpReplace($sData, $sRegEx, $sReplace, $iCount) Return SetError(@error, @extended, $sRet) EndIf ; unique identifier Local $sUStart = "<" & Chr(1) & "@U@" & Chr(1) & ">" Local $sUEnd = "</" & Chr(1) & "@U@" & Chr(1) & ">" Local $sLStart = "<" & Chr(1) & "@L@" & Chr(1) & ">" Local $sLEnd = "</" & Chr(1) & "@L@" & Chr(1) & ">" ; modify replace string Local $sTmp = $sReplace $sTmp = StringRegExpReplace($sTmp, "(?i)([\\$]u)([\$\\]{?\d+\}?)", $sUStart & "$2" & $sUEnd) $sTmp = StringRegExpReplace($sTmp, "(?i)([\\$]l)([\$\\]{?\d+\}?)", $sLStart & "$2" & $sLEnd) Local $sRepStr = StringRegExpReplace($sData, $sRegEx, $sTmp, $iCount) Local $iExtended = @extended ; get upper and lower matches with unique identifier Local $aMatchUpper = StringRegExp($sRepStr, "(\Q" & $sUStart & "\E.*?\Q" & $sUEnd & "\E)", $iGlobalMatch) Local $aMatchLower = StringRegExp($sRepStr, "(\Q" & $sLStart & "\E.*?\Q" & $sLEnd & "\E)", $iGlobalMatch) ; no need to worry about case Local $aMUpUnique, $aMLrUnique If IsArray($aMatchUpper) Then $aMUpUnique = _ArrayUnique($aMatchUpper, 0, 0, 0, $ARRAYUNIQUE_NOCOUNT) EndIf If IsArray($aMatchLower) Then $aMLrUnique = _ArrayUnique($aMatchLower, 0, 0, 0, $ARRAYUNIQUE_NOCOUNT) EndIf $sRet = $sRepStr Local $sMatch For $i = 0 To UBound($aMUpUnique) - 1 $sMatch = StringRegExpReplace($aMUpUnique[$i], "\Q" & $sUStart & "\E|\Q" & $sUEnd & "\E", "") $sRet = StringReplace($sRet, $aMUpUnique[$i], StringUpper($sMatch), $iCount) Next For $i = 0 To UBound($aMLrUnique) - 1 $sMatch = StringRegExpReplace($aMLrUnique[$i], "\Q" & $sLStart & "\E|\Q" & $sLEnd & "\E", "") $sRet = StringReplace($sRet, $aMLrUnique[$i], StringLower($sMatch), $iCount) Next Return SetExtended($iExtended, $sRet) EndFunc  
  15. Like
    SmOke_N got a reaction from argumentum in StringRegExpReplace with Upper/Lower option   
    Yep, one of those moments where I forgot that \u or \l doesn't work with our PCRE engine 😞.
    So I *slap-sticked* some code together to achieve what I needed on the fly.
    This is truly ugly IMO, but if you're not doing a lot of string manipulation concatenations it's ok.  I know I wrote some pcre funcs in a dll back in the day for my personal use to be able to do some things like this, but of course I can't find it... So native it is.
    Anyway, I added this to my personal chars au3, thus the name you'll see.
    Please test and criticize away, like I said, it was a quick mod and it's A-L-O-T of regex this and regex that ... but maybe it's useful for someone.
    #include <StringConstants.au3> #include <Array.au3> ; #FUNCTION# ==================================================================================================================== ; Name ..........: _AutChars_RegExpReplaceEx ; Description ...: Allows StringRegExpReplace replace with pattern to do upper/lower ; Syntax ........: _AutChars_RegExpReplaceEx($sData, $sRegEx, $sReplace[, $iCount = 0]) ; Parameters ....: $sData - The string to check ; $sRegEx - The regular expression to compare. See StringRegExp for pattern definition characters. ; $sReplace - The text to replace the regular expression matching text with ; $iCount - Number of replacements. Default is 0 for global replacement ; Return values .: Success - an updated string based on regular expressions ; @extended = number of replacements performed ; Author ........: SmOke_N (Ron Nielsen.. Ron.SMACKThatApp@GMail.com) ; Modified ......: ; Related .......: See StringRegExpReplace() ; Remarks .......: Will only work with \u or \l such as \u$2 in replace with pattern ; In my opinion, this is a pretty abusive way to achieve this, might be fine for small jobs ; but the overhead would be immense ; Example .......: _AutChars_RegExpReplaceEx("abcdAbcefg", "abc", "\u$0") will return ABCdAbcefg ; =============================================================================================================================== Func _AutChars_RegExpReplaceEx($sData, $sRegEx, $sReplace, $iCount = 0) ; work in progress Local Const $iGlobalMatch = $STR_REGEXPARRAYGLOBALMATCH Local $sRet = "" Local Const $sMatchRE = "[\\$](?:u|l)[\$\\]{?\d+\}?" If Not StringRegExp($sReplace, $sMatchRE) Then $sRet = StringRegExpReplace($sData, $sRegEx, $sReplace, $iCount) Return SetError(@error, @extended, $sRet) EndIf ; unique identifier Local $sUStart = "<" & Chr(1) & "@U@" & Chr(1) & ">" Local $sUEnd = "</" & Chr(1) & "@U@" & Chr(1) & ">" Local $sLStart = "<" & Chr(1) & "@L@" & Chr(1) & ">" Local $sLEnd = "</" & Chr(1) & "@L@" & Chr(1) & ">" ; modify replace string Local $sTmp = $sReplace $sTmp = StringRegExpReplace($sTmp, "(?i)([\\$]u)([\$\\]{?\d+\}?)", $sUStart & "$2" & $sUEnd) $sTmp = StringRegExpReplace($sTmp, "(?i)([\\$]l)([\$\\]{?\d+\}?)", $sLStart & "$2" & $sLEnd) Local $sRepStr = StringRegExpReplace($sData, $sRegEx, $sTmp, $iCount) Local $iExtended = @extended ; get upper and lower matches with unique identifier Local $aMatchUpper = StringRegExp($sRepStr, "(\Q" & $sUStart & "\E.*?\Q" & $sUEnd & "\E)", $iGlobalMatch) Local $aMatchLower = StringRegExp($sRepStr, "(\Q" & $sLStart & "\E.*?\Q" & $sLEnd & "\E)", $iGlobalMatch) ; no need to worry about case Local $aMUpUnique, $aMLrUnique If IsArray($aMatchUpper) Then $aMUpUnique = _ArrayUnique($aMatchUpper, 0, 0, 0, $ARRAYUNIQUE_NOCOUNT) EndIf If IsArray($aMatchLower) Then $aMLrUnique = _ArrayUnique($aMatchLower, 0, 0, 0, $ARRAYUNIQUE_NOCOUNT) EndIf $sRet = $sRepStr Local $sMatch For $i = 0 To UBound($aMUpUnique) - 1 $sMatch = StringRegExpReplace($aMUpUnique[$i], "\Q" & $sUStart & "\E|\Q" & $sUEnd & "\E", "") $sRet = StringReplace($sRet, $aMUpUnique[$i], StringUpper($sMatch), $iCount) Next For $i = 0 To UBound($aMLrUnique) - 1 $sMatch = StringRegExpReplace($aMLrUnique[$i], "\Q" & $sLStart & "\E|\Q" & $sLEnd & "\E", "") $sRet = StringReplace($sRet, $aMLrUnique[$i], StringLower($sMatch), $iCount) Next Return SetExtended($iExtended, $sRet) EndFunc  
  16. Like
    SmOke_N reacted to SOLVE-SMART in StringRegExpReplace with Upper/Lower option   
    Thank you @SmOke_N, this is really helpful and I will definitely give it a try, making tests and enjoy it 😅 .

    Best regards
    Sven
  17. Thanks
    SmOke_N got a reaction from SOLVE-SMART in StringRegExpReplace with Upper/Lower option   
    Yep, one of those moments where I forgot that \u or \l doesn't work with our PCRE engine 😞.
    So I *slap-sticked* some code together to achieve what I needed on the fly.
    This is truly ugly IMO, but if you're not doing a lot of string manipulation concatenations it's ok.  I know I wrote some pcre funcs in a dll back in the day for my personal use to be able to do some things like this, but of course I can't find it... So native it is.
    Anyway, I added this to my personal chars au3, thus the name you'll see.
    Please test and criticize away, like I said, it was a quick mod and it's A-L-O-T of regex this and regex that ... but maybe it's useful for someone.
    #include <StringConstants.au3> #include <Array.au3> ; #FUNCTION# ==================================================================================================================== ; Name ..........: _AutChars_RegExpReplaceEx ; Description ...: Allows StringRegExpReplace replace with pattern to do upper/lower ; Syntax ........: _AutChars_RegExpReplaceEx($sData, $sRegEx, $sReplace[, $iCount = 0]) ; Parameters ....: $sData - The string to check ; $sRegEx - The regular expression to compare. See StringRegExp for pattern definition characters. ; $sReplace - The text to replace the regular expression matching text with ; $iCount - Number of replacements. Default is 0 for global replacement ; Return values .: Success - an updated string based on regular expressions ; @extended = number of replacements performed ; Author ........: SmOke_N (Ron Nielsen.. Ron.SMACKThatApp@GMail.com) ; Modified ......: ; Related .......: See StringRegExpReplace() ; Remarks .......: Will only work with \u or \l such as \u$2 in replace with pattern ; In my opinion, this is a pretty abusive way to achieve this, might be fine for small jobs ; but the overhead would be immense ; Example .......: _AutChars_RegExpReplaceEx("abcdAbcefg", "abc", "\u$0") will return ABCdAbcefg ; =============================================================================================================================== Func _AutChars_RegExpReplaceEx($sData, $sRegEx, $sReplace, $iCount = 0) ; work in progress Local Const $iGlobalMatch = $STR_REGEXPARRAYGLOBALMATCH Local $sRet = "" Local Const $sMatchRE = "[\\$](?:u|l)[\$\\]{?\d+\}?" If Not StringRegExp($sReplace, $sMatchRE) Then $sRet = StringRegExpReplace($sData, $sRegEx, $sReplace, $iCount) Return SetError(@error, @extended, $sRet) EndIf ; unique identifier Local $sUStart = "<" & Chr(1) & "@U@" & Chr(1) & ">" Local $sUEnd = "</" & Chr(1) & "@U@" & Chr(1) & ">" Local $sLStart = "<" & Chr(1) & "@L@" & Chr(1) & ">" Local $sLEnd = "</" & Chr(1) & "@L@" & Chr(1) & ">" ; modify replace string Local $sTmp = $sReplace $sTmp = StringRegExpReplace($sTmp, "(?i)([\\$]u)([\$\\]{?\d+\}?)", $sUStart & "$2" & $sUEnd) $sTmp = StringRegExpReplace($sTmp, "(?i)([\\$]l)([\$\\]{?\d+\}?)", $sLStart & "$2" & $sLEnd) Local $sRepStr = StringRegExpReplace($sData, $sRegEx, $sTmp, $iCount) Local $iExtended = @extended ; get upper and lower matches with unique identifier Local $aMatchUpper = StringRegExp($sRepStr, "(\Q" & $sUStart & "\E.*?\Q" & $sUEnd & "\E)", $iGlobalMatch) Local $aMatchLower = StringRegExp($sRepStr, "(\Q" & $sLStart & "\E.*?\Q" & $sLEnd & "\E)", $iGlobalMatch) ; no need to worry about case Local $aMUpUnique, $aMLrUnique If IsArray($aMatchUpper) Then $aMUpUnique = _ArrayUnique($aMatchUpper, 0, 0, 0, $ARRAYUNIQUE_NOCOUNT) EndIf If IsArray($aMatchLower) Then $aMLrUnique = _ArrayUnique($aMatchLower, 0, 0, 0, $ARRAYUNIQUE_NOCOUNT) EndIf $sRet = $sRepStr Local $sMatch For $i = 0 To UBound($aMUpUnique) - 1 $sMatch = StringRegExpReplace($aMUpUnique[$i], "\Q" & $sUStart & "\E|\Q" & $sUEnd & "\E", "") $sRet = StringReplace($sRet, $aMUpUnique[$i], StringUpper($sMatch), $iCount) Next For $i = 0 To UBound($aMLrUnique) - 1 $sMatch = StringRegExpReplace($aMLrUnique[$i], "\Q" & $sLStart & "\E|\Q" & $sLEnd & "\E", "") $sRet = StringReplace($sRet, $aMLrUnique[$i], StringLower($sMatch), $iCount) Next Return SetExtended($iExtended, $sRet) EndFunc  
  18. Like
    SmOke_N got a reaction from twothirtyone in _GUICtrlButton_SetSplitInfo   
    AutoIt3.exe ended.rc:-1073740771
    Same error, I'm gonna take a nap before I look...
  19. Like
    SmOke_N got a reaction from ioa747 in _GUICtrlButton_SetSplitInfo   
    AutoIt3.exe ended.rc:-1073740771
    Same error, I'm gonna take a nap before I look...
  20. Like
    SmOke_N got a reaction from argumentum in Log onto wifi using wpa2-enterprise credentials   
    You can't directly connect to your wifi through the command prompt (eg. netsh), however there's always some work around.
    I've never worked with NETSH before, but I played around for a while with it.  I'll be honest, I've never been a fan of using the command prompts of apps, for some reason I feel like I have less control.
    These are make-shift udfs I just put together, some were my practice funcs, but if you look at the ones I point out at the top, they may help you.  The last one, if the first two function calls fail, is one where you can create a tmp xml file, add that profile, run the netsh command then delete the tmp xml file.  All of these worked on the my Windows 10 machine.  Should work on Windows 11 too from what I was reading.
    ;~ #RequireAdmin ; may need to have admin priviliges #include-once #include <AutoItConstants.au3> #include <StringConstants.au3> #include <FileConstants.au3> Global $gsMySSID_WifiName = "MyNetwork" ; obviously change it to your own network name If Not _AutNETSH_WLan_IsConnectedBy("SSID", $gsMySSID_WifiName) Then ConsoleWrite("Going to attempt to connect.." & @CRLF) _AutNETSH_WLan_ConnectionRequest($gsMySSID_WifiName) Sleep(5000) ; give it 5 seconds and check if it worked If Not _AutNETSH_WLan_IsConnectedBy("SSID", $gsMySSID_WifiName) Then ConsoleWrite("Still not connected, does the profile exist yet?" & @CRLF & _ "If the profile doesn't exist, or the password/username changes often, try using: " & @CRLF & _ "_AutNETSH_WLan_AddConnectionRequest() below somwwhere..." & @CRLF) EndIf EndIf Func _AutNETSH_WLan_IsConnectedBy($sType, $sFind, $sWkDir = Default) ; because @error may return error text ; we'll just return yes or no string If $sWkDir = Default Or $sWkDir = -1 Then $sWkDir = @UserProfileDir EndIf Local $iPID = Run("netsh wlan show interface", $sWkDir, @SW_HIDE, BitOR($STDERR_CHILD, $STDOUT_CHILD)) Local $aRead = _AutNETSH_WLan_STDRead($iPID) If @error Then Return SetError(1, 0, StringRegExpReplace($aRead[1], "(?s)^\s*|\s*$", "")) EndIf ; escape type and value to find $sType = __AutNETSH_WLan_EscapeDelimiters($sType) $sFind = __AutNETSH_WLan_EscapeDelimiters($sFind) Local $sStRE = "(*UCP)(?mi)\h*" & $sType & "\h*\:\h*" & $sFind & "\h*$" Return (StringRegExp($aRead[0], $sStRE) <> 0) EndFunc Func _AutNETSH_WLan_IsConnected($sWkDir = Default) ; because @error may return error text ; we'll just return yes or no string If $sWkDir = Default Or $sWkDir = -1 Then $sWkDir = @UserProfileDir EndIf Local $iPID = Run("netsh wlan show interface", $sWkDir, @SW_HIDE, BitOR($STDERR_CHILD, $STDOUT_CHILD)) Local $aRead = _AutNETSH_WLan_STDRead($iPID) If @error Then Return SetError(1, 0, StringRegExpReplace($aRead[1], "(?s)^\s*|\s*$", "")) EndIf Local Const $sStRE = "(*UCP)(?mi)\h*state\h*\:\h*(\w+)" Local $aRet = StringRegExp($aRead[0], $sStRE, $STR_REGEXPARRAYGLOBALMATCH) If Not IsArray($aRet) Then Return SetError(2, 0, "") EndIf Return $aRet[0] EndFunc Func _AutNETSH_WLan_ConnectionRequest($sSSID, $sWkDir = Default) If $sWkDir = Default Or $sWkDir = -1 Then $sWkDir = @UserProfileDir EndIf ; connect to profile Local $iPID = Run('netsh wlan connect name="' & $sSSID & '"', $sWkDir, @SW_HIDE, BitOR($STDERR_CHILD, $STDOUT_CHILD)) Local $aRead = _AutNETSH_WLan_STDRead($iPID) If @error Then Return SetError(1, 0, StringRegExpReplace($aRead[1], "(?s)^\s*|\s*$", "")) EndIf Return $aRead[0] EndFunc Func _AutNETSH_WLan_AddConnectionRequest($sSSID, $sPassword, $sConnectionType = Default, _ $sConnectionMode = Default, $sAuthentication = Default, _ $sEncryption = Default, $sUseOneX = Default, $sKeyType = Default, _ $sProtected = Default, $sEnableRandomization = Default, _ $sWkDir = Default, $sTmpPath = Default) If $sConnectionType = Default Or $sConnectionType = -1 Then $sConnectionType = "ESS" EndIf If $sConnectionMode = Default Or $sConnectionMode = -1 Then $sConnectionMode = "auto" EndIf If $sAuthentication = Default Or $sAuthentication = -1 Then $sAuthentication = "WPA2PSK" EndIf If $sEncryption = Default Or $sEncryption = -1 Then $sEncryption = "AES" EndIf If $sUseOneX = Default Or $sUseOneX = -1 Then $sUseOneX = "false" EndIf If $sKeyType = Default Or $sKeyType = -1 Then $sKeyType = "passPhrase" EndIf If $sProtected = Default Or $sProtected = -1 Then $sProtected = "false" EndIf If $sEnableRandomization = Default Or $sEnableRandomization = -1 Then $sEnableRandomization = "false" EndIf If $sWkDir = Default Or $sWkDir = -1 Then $sWkDir = @UserProfileDir EndIf If $sTmpPath = Default Or $sTmpPath = -1 Or Not FileExists($sTmpPath) Then $sTmpPath = @ScriptDir EndIf Local $sXMLFile = "WLAN." & StringRegExpReplace($sSSID, "(*UCP)\W", "") $sXMLFile &= ".tmp(" & @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC & @MSEC & ").xml" Local $sOutXML = StringRegExpReplace($sTmpPath, "[\\/]+$", "") & "\" & $sXMLFile Local $sXML = "" $sXML &= '<?xml version="1.0"?>' & @CRLF $sXML &= ' <WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">' & @CRLF $sXML &= ' <name>' & $sSSID & '</name>' & @CRLF $sXML &= ' <SSIDConfig>' & @CRLF $sXML &= ' <SSID>' & @CRLF $sXML &= ' <name>' & $sSSID & '</name>' & @CRLF $sXML &= ' </SSID>' & @CRLF $sXML &= ' </SSIDConfig>' & @CRLF $sXML &= ' <connectionType>' & $sConnectionType & '</connectionType>' & @CRLF $sXML &= ' <connectionMode>' & $sConnectionMode & '</connectionMode>' & @CRLF $sXML &= ' <MSM>' & @CRLF $sXML &= ' <security>' & @CRLF $sXML &= ' <authEncryption>' & @CRLF $sXML &= ' <authentication>' & $sAuthentication & '</authentication>' & @CRLF $sXML &= ' <encryption>' $sEncryption & '</encryption>' & @CRLF $sXML &= ' <useOneX>' & $sUseOneX & '</useOneX>' & @CRLF $sXML &= ' </authEncryption>' & @CRLF $sXML &= ' <sharedKey>' & @CRLF $sXML &= ' <keyType>' & $sKeyType & '</keyType>' & @CRLF $sXML &= ' <protected>' & $sProtected & '</protected>' & @CRLF $sXML &= ' <keyMaterial>' & $sPassword & '</keyMaterial>' & @CRLF $sXML &= ' </sharedKey>' & @CRLF $sXML &= ' </security>' & @CRLF $sXML &= ' </MSM>' & @CRLF $sXML &= ' <MacRandomization xmlns="http://www.microsoft.com/networking/WLAN/profile/v3">' & @CRLF $sXML &= ' <enableRandomization>' & $sEnableRandomization & '</enableRandomization>' & @CRLF $sXML &= ' </MacRandomization>' & @CRLF $sXML &= '</WLANProfile>' Local $hOpen = FileOpen($sOutXML, $FO_OVERWRITE) FileWrite($hOpen, $sXML) FileClose($hOpen) ; add profile to cache Local $iPID = Run('netsh wlan add profile filename="' & $sOutXML & '"', $sWkDir, @SW_HIDE, BitOR($STDERR_CHILD, $STDOUT_CHILD)) Local $aRead = _AutNETSH_WLan_STDRead($iPID) If @error Then FileDelete($sOutXML) Return SetError(1, 0, StringRegExpReplace($aRead[1], "(?s)^\s*|\s*$", "")) EndIf Local $sRet = $aRead[0] ; connect to profile $iPID = Run('netsh wlan connect name="' & $sSSID & '"', $sWkDir, @SW_HIDE, BitOR($STDERR_CHILD, $STDOUT_CHILD)) $aRead = _AutNETSH_WLan_STDRead($iPID) If @error Then FileDelete($sOutXML) Return SetError(2, 0, StringRegExpReplace($aRead[1], "(?s)^\s*|\s*$", "")) EndIf FileDelete($sOutXML) $sRet &= " : " & $aRead[0] Return $sRet EndFunc Func _AutNETSH_WLan_ShowNetworks($sWkDir = Default) ; return network array If $sWkDir = Default Or $sWkDir = -1 Then $sWkDir = @UserProfileDir EndIf Local $iPID = Run("netsh wlan show networks", $sWkDir, @SW_HIDE, BitOR($STDERR_CHILD, $STDOUT_CHILD)) Local $aRead = _AutNETSH_WLan_STDRead($iPID) If @error Or Not IsArray($aRead) Then Return SetError(1, @error, StringRegExpReplace($aRead[1], "(?s)^\s*|\s*$", "")) EndIf Local Const $sSSIDRE = "(?si)(SSID\h*\d+\h*\:\h*.+?)(?:\v{3,}|$)" Local $aSSIDs = StringRegExp($aRead[0], $sSSIDRE, $STR_REGEXPARRAYGLOBALMATCH) If @error Or Not IsArray($aSSIDs) Then Return SetError(2, @error, "") EndIf Local $aHeaders = __AutNETSH_WLan_stdoutgetheader($aSSIDs) If @error Then Return SetError(3, @error, "") EndIf Local $aHData = __AutNETSH_WLan_stdoutgethdata($aSSIDs, $aHeaders) If @error Then Return SetError(4, @error, "") EndIf Return $aHData EndFunc ; See RunAs() in help file, may need to sign on as admin acct Func _AutNETSH_WLan_ShowNetworksAsUser($sUserName, $sDomain, $sPassword, $sLogonFlag, $sWkDir = Default) ; return network array If $sWkDir = Default Or $sWkDir = -1 Then $sWkDir = @UserProfileDir EndIf Local $iPID = RunAs($sUserName, $sDomain, $sPassword, $sLogonFlag, _ "netsh wlan show networks", $sWkDir, @SW_HIDE, BitOR($STDERR_CHILD, $STDOUT_CHILD)) Local $aRead = _AutNETSH_WLan_STDRead($iPID) If @error Or Not IsArray($aRead) Then Return SetError(1, 0, StringRegExpReplace($aRead[1], "(?s)^\s*|\s*$", "")) EndIf Local Const $sSSIDRE = "(?si)(SSID\h*\d+\h*\:\h*.+?)(?:\v{3,}|$)" Local $aSSIDs = StringRegExp($aRead[0], $sSSIDRE, $STR_REGEXPARRAYGLOBALMATCH) If @error Or Not IsArray($aSSIDs) Then Return SetError(2, @error, "") EndIf Local $aHeaders = __AutNETSH_WLan_stdoutgetheader($aSSIDs) If @error Then Return SetError(3, @error, "") EndIf Local $aHData = __AutNETSH_WLan_stdoutgethdata($aSSIDs, $aHeaders) If @error Then Return SetError(4, @error, "") EndIf Return $aHData EndFunc Func _AutNETSH_WLan_STDRead($iPID) $iPID = ProcessExists($iPID) If Not $iPID Then Return SetError(1, 0, 0) EndIf Local $sTmp, $sORead, $sOErr While ProcessExists($iPID) $sTmp = StdoutRead($iPID) If @error Then $sOErr = StderrRead($iPID) ExitLoop EndIf $sORead &= $sTmp WEnd ; clean up leading and traling $sORead = StringRegExpReplace($sORead, "(?s)^\s*|\s*$", "") $sOErr = StringRegExpReplace($sOErr, "(?s)^\s*|\s*$", "") Local $aRet[2] = [$sORead, $sOErr] If StringLen($sORead) = 0 Then Return SetError(1, 0, $aRet) EndIf Return $aRet EndFunc Func __AutNETSH_WLan_stdoutgetheader(ByRef $aData) If Not IsArray($aData) Then Return SetError(1, 0, 0) EndIf ; how many heades, some will have more/less based on connection type Local $iExt, $iHeaderCount = 0, $aHeaders For $i = 0 To UBound($aData) - 1 StringRegExpReplace($aData[$i], "(?m)\h+\:", "") $iExt = @extended If $iExt > $iHeaderCount Then $iHeaderCount = $iExt $aHeaders = StringRegExp($aData[$i], "(?m)\h*(.+?)\h+\:", $STR_REGEXPARRAYGLOBALMATCH) If IsArray($aHeaders) Then For $j = 0 To UBound($aHeaders) - 1 If StringInStr($aHeaders[$j], "SSID") Then $aHeaders[$j] = "SSID" ExitLoop EndIf Next EndIf EndIf Next If $iHeaderCount = 0 Then Return SetError(2, 0, 0) EndIf Return SetExtended($iHeaderCount, $aHeaders) EndFunc Func __AutNETSH_WLan_stdoutgethdata(ByRef $aData, ByRef $aHeaders) If Not IsArray($aData) Then Return SetError(1, 0, 0) EndIf If Not IsArray($aHeaders) Then Return SetError(2, 0, 0) EndIf ; [0][n] = headers Local $aRet[UBound($aData) + 1][UBound($aHeaders)] ; fill headers into ret array For $i = 0 To UBound($aHeaders) - 1 $aRet[0][$i] = $aHeaders[$i] ; turn headers into escaped chars $aHeaders[$i] = __AutNETSH_WLan_EscapeDelimiters($aHeaders[$i]) Next Local $aFound, $aLines, $iEnum, $iColCount = 0 ; start at 1, 0 is headers For $i = 0 To UBound($aData) - 1 $iEnum = 0 ; split into individual rows $aLines = StringRegExp($aData[$i], "\h*(.+?)\h*(\v+|$)", $STR_REGEXPARRAYGLOBALMATCH) For $x = 0 To UBound($aLines) - 1 For $j = 0 To UBound($aHeaders) - 1 If StringRegExp($aLines[$x], "(?i)^\h*" & $aHeaders[$j]) Then $aFound = StringRegExp($aLines[$x], "(?mi)\h*" & $aHeaders[$j] & ".*?\:\h*(.+?)\h*$", $STR_REGEXPARRAYGLOBALMATCH) If @error Or Not IsArray($aFound) Then ContinueLoop $aRet[$i + 1][$j] = $aFound[0] $iEnum += 1 ExitLoop EndIf Next Next If $iEnum > 0 Then $iColCount += 1 Next If $iColCount < UBound($aData) Then ; oops EndIf Return $aRet EndFunc Func __AutNETSH_WLan_EscapeDelimiters($sData) Local Const $sRE = "([\\\.\^\$\|\[|\]\(\)\{\}\*\+\?\#])" Local Const $sRep = "\\$1" Return StringRegExpReplace($sData, $sRE, $sRep) EndFunc If you're going to do this across a private network, you may want to look into RunAs(), I have one example function in there with that that you can kind of get the idea from.
    Anyway, I did more than I thought I would for something I can never see myself using... so hope it helps.
    Edit:
    You may need to change this section for enterprise:
    $sXML &= ' <authEncryption>' & @CRLF $sXML &= ' <authentication>WPA2PSK</authentication>' & @CRLF $sXML &= ' <encryption>AES</encryption>' & @CRLF $sXML &= ' <useOneX>false</useOneX>' & @CRLF $sXML &= ' </authEncryption>' & @CRLF I'm to lazy to make something that does it atm.
    Edit2:
    Changed _AutNETSH_WLan_AddConnectionRequest() so you can customize all the xml options if needed.  I'm not 100% on WPA2 Enterprise, but it looks like you can change Authentication = WPA2 and Encryption to TKIP... anyway, really really really done this time 
  21. Like
    SmOke_N got a reaction from rsn in Log onto wifi using wpa2-enterprise credentials   
    You can't directly connect to your wifi through the command prompt (eg. netsh), however there's always some work around.
    I've never worked with NETSH before, but I played around for a while with it.  I'll be honest, I've never been a fan of using the command prompts of apps, for some reason I feel like I have less control.
    These are make-shift udfs I just put together, some were my practice funcs, but if you look at the ones I point out at the top, they may help you.  The last one, if the first two function calls fail, is one where you can create a tmp xml file, add that profile, run the netsh command then delete the tmp xml file.  All of these worked on the my Windows 10 machine.  Should work on Windows 11 too from what I was reading.
    ;~ #RequireAdmin ; may need to have admin priviliges #include-once #include <AutoItConstants.au3> #include <StringConstants.au3> #include <FileConstants.au3> Global $gsMySSID_WifiName = "MyNetwork" ; obviously change it to your own network name If Not _AutNETSH_WLan_IsConnectedBy("SSID", $gsMySSID_WifiName) Then ConsoleWrite("Going to attempt to connect.." & @CRLF) _AutNETSH_WLan_ConnectionRequest($gsMySSID_WifiName) Sleep(5000) ; give it 5 seconds and check if it worked If Not _AutNETSH_WLan_IsConnectedBy("SSID", $gsMySSID_WifiName) Then ConsoleWrite("Still not connected, does the profile exist yet?" & @CRLF & _ "If the profile doesn't exist, or the password/username changes often, try using: " & @CRLF & _ "_AutNETSH_WLan_AddConnectionRequest() below somwwhere..." & @CRLF) EndIf EndIf Func _AutNETSH_WLan_IsConnectedBy($sType, $sFind, $sWkDir = Default) ; because @error may return error text ; we'll just return yes or no string If $sWkDir = Default Or $sWkDir = -1 Then $sWkDir = @UserProfileDir EndIf Local $iPID = Run("netsh wlan show interface", $sWkDir, @SW_HIDE, BitOR($STDERR_CHILD, $STDOUT_CHILD)) Local $aRead = _AutNETSH_WLan_STDRead($iPID) If @error Then Return SetError(1, 0, StringRegExpReplace($aRead[1], "(?s)^\s*|\s*$", "")) EndIf ; escape type and value to find $sType = __AutNETSH_WLan_EscapeDelimiters($sType) $sFind = __AutNETSH_WLan_EscapeDelimiters($sFind) Local $sStRE = "(*UCP)(?mi)\h*" & $sType & "\h*\:\h*" & $sFind & "\h*$" Return (StringRegExp($aRead[0], $sStRE) <> 0) EndFunc Func _AutNETSH_WLan_IsConnected($sWkDir = Default) ; because @error may return error text ; we'll just return yes or no string If $sWkDir = Default Or $sWkDir = -1 Then $sWkDir = @UserProfileDir EndIf Local $iPID = Run("netsh wlan show interface", $sWkDir, @SW_HIDE, BitOR($STDERR_CHILD, $STDOUT_CHILD)) Local $aRead = _AutNETSH_WLan_STDRead($iPID) If @error Then Return SetError(1, 0, StringRegExpReplace($aRead[1], "(?s)^\s*|\s*$", "")) EndIf Local Const $sStRE = "(*UCP)(?mi)\h*state\h*\:\h*(\w+)" Local $aRet = StringRegExp($aRead[0], $sStRE, $STR_REGEXPARRAYGLOBALMATCH) If Not IsArray($aRet) Then Return SetError(2, 0, "") EndIf Return $aRet[0] EndFunc Func _AutNETSH_WLan_ConnectionRequest($sSSID, $sWkDir = Default) If $sWkDir = Default Or $sWkDir = -1 Then $sWkDir = @UserProfileDir EndIf ; connect to profile Local $iPID = Run('netsh wlan connect name="' & $sSSID & '"', $sWkDir, @SW_HIDE, BitOR($STDERR_CHILD, $STDOUT_CHILD)) Local $aRead = _AutNETSH_WLan_STDRead($iPID) If @error Then Return SetError(1, 0, StringRegExpReplace($aRead[1], "(?s)^\s*|\s*$", "")) EndIf Return $aRead[0] EndFunc Func _AutNETSH_WLan_AddConnectionRequest($sSSID, $sPassword, $sConnectionType = Default, _ $sConnectionMode = Default, $sAuthentication = Default, _ $sEncryption = Default, $sUseOneX = Default, $sKeyType = Default, _ $sProtected = Default, $sEnableRandomization = Default, _ $sWkDir = Default, $sTmpPath = Default) If $sConnectionType = Default Or $sConnectionType = -1 Then $sConnectionType = "ESS" EndIf If $sConnectionMode = Default Or $sConnectionMode = -1 Then $sConnectionMode = "auto" EndIf If $sAuthentication = Default Or $sAuthentication = -1 Then $sAuthentication = "WPA2PSK" EndIf If $sEncryption = Default Or $sEncryption = -1 Then $sEncryption = "AES" EndIf If $sUseOneX = Default Or $sUseOneX = -1 Then $sUseOneX = "false" EndIf If $sKeyType = Default Or $sKeyType = -1 Then $sKeyType = "passPhrase" EndIf If $sProtected = Default Or $sProtected = -1 Then $sProtected = "false" EndIf If $sEnableRandomization = Default Or $sEnableRandomization = -1 Then $sEnableRandomization = "false" EndIf If $sWkDir = Default Or $sWkDir = -1 Then $sWkDir = @UserProfileDir EndIf If $sTmpPath = Default Or $sTmpPath = -1 Or Not FileExists($sTmpPath) Then $sTmpPath = @ScriptDir EndIf Local $sXMLFile = "WLAN." & StringRegExpReplace($sSSID, "(*UCP)\W", "") $sXMLFile &= ".tmp(" & @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC & @MSEC & ").xml" Local $sOutXML = StringRegExpReplace($sTmpPath, "[\\/]+$", "") & "\" & $sXMLFile Local $sXML = "" $sXML &= '<?xml version="1.0"?>' & @CRLF $sXML &= ' <WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">' & @CRLF $sXML &= ' <name>' & $sSSID & '</name>' & @CRLF $sXML &= ' <SSIDConfig>' & @CRLF $sXML &= ' <SSID>' & @CRLF $sXML &= ' <name>' & $sSSID & '</name>' & @CRLF $sXML &= ' </SSID>' & @CRLF $sXML &= ' </SSIDConfig>' & @CRLF $sXML &= ' <connectionType>' & $sConnectionType & '</connectionType>' & @CRLF $sXML &= ' <connectionMode>' & $sConnectionMode & '</connectionMode>' & @CRLF $sXML &= ' <MSM>' & @CRLF $sXML &= ' <security>' & @CRLF $sXML &= ' <authEncryption>' & @CRLF $sXML &= ' <authentication>' & $sAuthentication & '</authentication>' & @CRLF $sXML &= ' <encryption>' $sEncryption & '</encryption>' & @CRLF $sXML &= ' <useOneX>' & $sUseOneX & '</useOneX>' & @CRLF $sXML &= ' </authEncryption>' & @CRLF $sXML &= ' <sharedKey>' & @CRLF $sXML &= ' <keyType>' & $sKeyType & '</keyType>' & @CRLF $sXML &= ' <protected>' & $sProtected & '</protected>' & @CRLF $sXML &= ' <keyMaterial>' & $sPassword & '</keyMaterial>' & @CRLF $sXML &= ' </sharedKey>' & @CRLF $sXML &= ' </security>' & @CRLF $sXML &= ' </MSM>' & @CRLF $sXML &= ' <MacRandomization xmlns="http://www.microsoft.com/networking/WLAN/profile/v3">' & @CRLF $sXML &= ' <enableRandomization>' & $sEnableRandomization & '</enableRandomization>' & @CRLF $sXML &= ' </MacRandomization>' & @CRLF $sXML &= '</WLANProfile>' Local $hOpen = FileOpen($sOutXML, $FO_OVERWRITE) FileWrite($hOpen, $sXML) FileClose($hOpen) ; add profile to cache Local $iPID = Run('netsh wlan add profile filename="' & $sOutXML & '"', $sWkDir, @SW_HIDE, BitOR($STDERR_CHILD, $STDOUT_CHILD)) Local $aRead = _AutNETSH_WLan_STDRead($iPID) If @error Then FileDelete($sOutXML) Return SetError(1, 0, StringRegExpReplace($aRead[1], "(?s)^\s*|\s*$", "")) EndIf Local $sRet = $aRead[0] ; connect to profile $iPID = Run('netsh wlan connect name="' & $sSSID & '"', $sWkDir, @SW_HIDE, BitOR($STDERR_CHILD, $STDOUT_CHILD)) $aRead = _AutNETSH_WLan_STDRead($iPID) If @error Then FileDelete($sOutXML) Return SetError(2, 0, StringRegExpReplace($aRead[1], "(?s)^\s*|\s*$", "")) EndIf FileDelete($sOutXML) $sRet &= " : " & $aRead[0] Return $sRet EndFunc Func _AutNETSH_WLan_ShowNetworks($sWkDir = Default) ; return network array If $sWkDir = Default Or $sWkDir = -1 Then $sWkDir = @UserProfileDir EndIf Local $iPID = Run("netsh wlan show networks", $sWkDir, @SW_HIDE, BitOR($STDERR_CHILD, $STDOUT_CHILD)) Local $aRead = _AutNETSH_WLan_STDRead($iPID) If @error Or Not IsArray($aRead) Then Return SetError(1, @error, StringRegExpReplace($aRead[1], "(?s)^\s*|\s*$", "")) EndIf Local Const $sSSIDRE = "(?si)(SSID\h*\d+\h*\:\h*.+?)(?:\v{3,}|$)" Local $aSSIDs = StringRegExp($aRead[0], $sSSIDRE, $STR_REGEXPARRAYGLOBALMATCH) If @error Or Not IsArray($aSSIDs) Then Return SetError(2, @error, "") EndIf Local $aHeaders = __AutNETSH_WLan_stdoutgetheader($aSSIDs) If @error Then Return SetError(3, @error, "") EndIf Local $aHData = __AutNETSH_WLan_stdoutgethdata($aSSIDs, $aHeaders) If @error Then Return SetError(4, @error, "") EndIf Return $aHData EndFunc ; See RunAs() in help file, may need to sign on as admin acct Func _AutNETSH_WLan_ShowNetworksAsUser($sUserName, $sDomain, $sPassword, $sLogonFlag, $sWkDir = Default) ; return network array If $sWkDir = Default Or $sWkDir = -1 Then $sWkDir = @UserProfileDir EndIf Local $iPID = RunAs($sUserName, $sDomain, $sPassword, $sLogonFlag, _ "netsh wlan show networks", $sWkDir, @SW_HIDE, BitOR($STDERR_CHILD, $STDOUT_CHILD)) Local $aRead = _AutNETSH_WLan_STDRead($iPID) If @error Or Not IsArray($aRead) Then Return SetError(1, 0, StringRegExpReplace($aRead[1], "(?s)^\s*|\s*$", "")) EndIf Local Const $sSSIDRE = "(?si)(SSID\h*\d+\h*\:\h*.+?)(?:\v{3,}|$)" Local $aSSIDs = StringRegExp($aRead[0], $sSSIDRE, $STR_REGEXPARRAYGLOBALMATCH) If @error Or Not IsArray($aSSIDs) Then Return SetError(2, @error, "") EndIf Local $aHeaders = __AutNETSH_WLan_stdoutgetheader($aSSIDs) If @error Then Return SetError(3, @error, "") EndIf Local $aHData = __AutNETSH_WLan_stdoutgethdata($aSSIDs, $aHeaders) If @error Then Return SetError(4, @error, "") EndIf Return $aHData EndFunc Func _AutNETSH_WLan_STDRead($iPID) $iPID = ProcessExists($iPID) If Not $iPID Then Return SetError(1, 0, 0) EndIf Local $sTmp, $sORead, $sOErr While ProcessExists($iPID) $sTmp = StdoutRead($iPID) If @error Then $sOErr = StderrRead($iPID) ExitLoop EndIf $sORead &= $sTmp WEnd ; clean up leading and traling $sORead = StringRegExpReplace($sORead, "(?s)^\s*|\s*$", "") $sOErr = StringRegExpReplace($sOErr, "(?s)^\s*|\s*$", "") Local $aRet[2] = [$sORead, $sOErr] If StringLen($sORead) = 0 Then Return SetError(1, 0, $aRet) EndIf Return $aRet EndFunc Func __AutNETSH_WLan_stdoutgetheader(ByRef $aData) If Not IsArray($aData) Then Return SetError(1, 0, 0) EndIf ; how many heades, some will have more/less based on connection type Local $iExt, $iHeaderCount = 0, $aHeaders For $i = 0 To UBound($aData) - 1 StringRegExpReplace($aData[$i], "(?m)\h+\:", "") $iExt = @extended If $iExt > $iHeaderCount Then $iHeaderCount = $iExt $aHeaders = StringRegExp($aData[$i], "(?m)\h*(.+?)\h+\:", $STR_REGEXPARRAYGLOBALMATCH) If IsArray($aHeaders) Then For $j = 0 To UBound($aHeaders) - 1 If StringInStr($aHeaders[$j], "SSID") Then $aHeaders[$j] = "SSID" ExitLoop EndIf Next EndIf EndIf Next If $iHeaderCount = 0 Then Return SetError(2, 0, 0) EndIf Return SetExtended($iHeaderCount, $aHeaders) EndFunc Func __AutNETSH_WLan_stdoutgethdata(ByRef $aData, ByRef $aHeaders) If Not IsArray($aData) Then Return SetError(1, 0, 0) EndIf If Not IsArray($aHeaders) Then Return SetError(2, 0, 0) EndIf ; [0][n] = headers Local $aRet[UBound($aData) + 1][UBound($aHeaders)] ; fill headers into ret array For $i = 0 To UBound($aHeaders) - 1 $aRet[0][$i] = $aHeaders[$i] ; turn headers into escaped chars $aHeaders[$i] = __AutNETSH_WLan_EscapeDelimiters($aHeaders[$i]) Next Local $aFound, $aLines, $iEnum, $iColCount = 0 ; start at 1, 0 is headers For $i = 0 To UBound($aData) - 1 $iEnum = 0 ; split into individual rows $aLines = StringRegExp($aData[$i], "\h*(.+?)\h*(\v+|$)", $STR_REGEXPARRAYGLOBALMATCH) For $x = 0 To UBound($aLines) - 1 For $j = 0 To UBound($aHeaders) - 1 If StringRegExp($aLines[$x], "(?i)^\h*" & $aHeaders[$j]) Then $aFound = StringRegExp($aLines[$x], "(?mi)\h*" & $aHeaders[$j] & ".*?\:\h*(.+?)\h*$", $STR_REGEXPARRAYGLOBALMATCH) If @error Or Not IsArray($aFound) Then ContinueLoop $aRet[$i + 1][$j] = $aFound[0] $iEnum += 1 ExitLoop EndIf Next Next If $iEnum > 0 Then $iColCount += 1 Next If $iColCount < UBound($aData) Then ; oops EndIf Return $aRet EndFunc Func __AutNETSH_WLan_EscapeDelimiters($sData) Local Const $sRE = "([\\\.\^\$\|\[|\]\(\)\{\}\*\+\?\#])" Local Const $sRep = "\\$1" Return StringRegExpReplace($sData, $sRE, $sRep) EndFunc If you're going to do this across a private network, you may want to look into RunAs(), I have one example function in there with that that you can kind of get the idea from.
    Anyway, I did more than I thought I would for something I can never see myself using... so hope it helps.
    Edit:
    You may need to change this section for enterprise:
    $sXML &= ' <authEncryption>' & @CRLF $sXML &= ' <authentication>WPA2PSK</authentication>' & @CRLF $sXML &= ' <encryption>AES</encryption>' & @CRLF $sXML &= ' <useOneX>false</useOneX>' & @CRLF $sXML &= ' </authEncryption>' & @CRLF I'm to lazy to make something that does it atm.
    Edit2:
    Changed _AutNETSH_WLan_AddConnectionRequest() so you can customize all the xml options if needed.  I'm not 100% on WPA2 Enterprise, but it looks like you can change Authentication = WPA2 and Encryption to TKIP... anyway, really really really done this time 
  22. Like
    SmOke_N got a reaction from guaikahenguai in Log onto wifi using wpa2-enterprise credentials   
    You can't directly connect to your wifi through the command prompt (eg. netsh), however there's always some work around.
    I've never worked with NETSH before, but I played around for a while with it.  I'll be honest, I've never been a fan of using the command prompts of apps, for some reason I feel like I have less control.
    These are make-shift udfs I just put together, some were my practice funcs, but if you look at the ones I point out at the top, they may help you.  The last one, if the first two function calls fail, is one where you can create a tmp xml file, add that profile, run the netsh command then delete the tmp xml file.  All of these worked on the my Windows 10 machine.  Should work on Windows 11 too from what I was reading.
    ;~ #RequireAdmin ; may need to have admin priviliges #include-once #include <AutoItConstants.au3> #include <StringConstants.au3> #include <FileConstants.au3> Global $gsMySSID_WifiName = "MyNetwork" ; obviously change it to your own network name If Not _AutNETSH_WLan_IsConnectedBy("SSID", $gsMySSID_WifiName) Then ConsoleWrite("Going to attempt to connect.." & @CRLF) _AutNETSH_WLan_ConnectionRequest($gsMySSID_WifiName) Sleep(5000) ; give it 5 seconds and check if it worked If Not _AutNETSH_WLan_IsConnectedBy("SSID", $gsMySSID_WifiName) Then ConsoleWrite("Still not connected, does the profile exist yet?" & @CRLF & _ "If the profile doesn't exist, or the password/username changes often, try using: " & @CRLF & _ "_AutNETSH_WLan_AddConnectionRequest() below somwwhere..." & @CRLF) EndIf EndIf Func _AutNETSH_WLan_IsConnectedBy($sType, $sFind, $sWkDir = Default) ; because @error may return error text ; we'll just return yes or no string If $sWkDir = Default Or $sWkDir = -1 Then $sWkDir = @UserProfileDir EndIf Local $iPID = Run("netsh wlan show interface", $sWkDir, @SW_HIDE, BitOR($STDERR_CHILD, $STDOUT_CHILD)) Local $aRead = _AutNETSH_WLan_STDRead($iPID) If @error Then Return SetError(1, 0, StringRegExpReplace($aRead[1], "(?s)^\s*|\s*$", "")) EndIf ; escape type and value to find $sType = __AutNETSH_WLan_EscapeDelimiters($sType) $sFind = __AutNETSH_WLan_EscapeDelimiters($sFind) Local $sStRE = "(*UCP)(?mi)\h*" & $sType & "\h*\:\h*" & $sFind & "\h*$" Return (StringRegExp($aRead[0], $sStRE) <> 0) EndFunc Func _AutNETSH_WLan_IsConnected($sWkDir = Default) ; because @error may return error text ; we'll just return yes or no string If $sWkDir = Default Or $sWkDir = -1 Then $sWkDir = @UserProfileDir EndIf Local $iPID = Run("netsh wlan show interface", $sWkDir, @SW_HIDE, BitOR($STDERR_CHILD, $STDOUT_CHILD)) Local $aRead = _AutNETSH_WLan_STDRead($iPID) If @error Then Return SetError(1, 0, StringRegExpReplace($aRead[1], "(?s)^\s*|\s*$", "")) EndIf Local Const $sStRE = "(*UCP)(?mi)\h*state\h*\:\h*(\w+)" Local $aRet = StringRegExp($aRead[0], $sStRE, $STR_REGEXPARRAYGLOBALMATCH) If Not IsArray($aRet) Then Return SetError(2, 0, "") EndIf Return $aRet[0] EndFunc Func _AutNETSH_WLan_ConnectionRequest($sSSID, $sWkDir = Default) If $sWkDir = Default Or $sWkDir = -1 Then $sWkDir = @UserProfileDir EndIf ; connect to profile Local $iPID = Run('netsh wlan connect name="' & $sSSID & '"', $sWkDir, @SW_HIDE, BitOR($STDERR_CHILD, $STDOUT_CHILD)) Local $aRead = _AutNETSH_WLan_STDRead($iPID) If @error Then Return SetError(1, 0, StringRegExpReplace($aRead[1], "(?s)^\s*|\s*$", "")) EndIf Return $aRead[0] EndFunc Func _AutNETSH_WLan_AddConnectionRequest($sSSID, $sPassword, $sConnectionType = Default, _ $sConnectionMode = Default, $sAuthentication = Default, _ $sEncryption = Default, $sUseOneX = Default, $sKeyType = Default, _ $sProtected = Default, $sEnableRandomization = Default, _ $sWkDir = Default, $sTmpPath = Default) If $sConnectionType = Default Or $sConnectionType = -1 Then $sConnectionType = "ESS" EndIf If $sConnectionMode = Default Or $sConnectionMode = -1 Then $sConnectionMode = "auto" EndIf If $sAuthentication = Default Or $sAuthentication = -1 Then $sAuthentication = "WPA2PSK" EndIf If $sEncryption = Default Or $sEncryption = -1 Then $sEncryption = "AES" EndIf If $sUseOneX = Default Or $sUseOneX = -1 Then $sUseOneX = "false" EndIf If $sKeyType = Default Or $sKeyType = -1 Then $sKeyType = "passPhrase" EndIf If $sProtected = Default Or $sProtected = -1 Then $sProtected = "false" EndIf If $sEnableRandomization = Default Or $sEnableRandomization = -1 Then $sEnableRandomization = "false" EndIf If $sWkDir = Default Or $sWkDir = -1 Then $sWkDir = @UserProfileDir EndIf If $sTmpPath = Default Or $sTmpPath = -1 Or Not FileExists($sTmpPath) Then $sTmpPath = @ScriptDir EndIf Local $sXMLFile = "WLAN." & StringRegExpReplace($sSSID, "(*UCP)\W", "") $sXMLFile &= ".tmp(" & @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC & @MSEC & ").xml" Local $sOutXML = StringRegExpReplace($sTmpPath, "[\\/]+$", "") & "\" & $sXMLFile Local $sXML = "" $sXML &= '<?xml version="1.0"?>' & @CRLF $sXML &= ' <WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">' & @CRLF $sXML &= ' <name>' & $sSSID & '</name>' & @CRLF $sXML &= ' <SSIDConfig>' & @CRLF $sXML &= ' <SSID>' & @CRLF $sXML &= ' <name>' & $sSSID & '</name>' & @CRLF $sXML &= ' </SSID>' & @CRLF $sXML &= ' </SSIDConfig>' & @CRLF $sXML &= ' <connectionType>' & $sConnectionType & '</connectionType>' & @CRLF $sXML &= ' <connectionMode>' & $sConnectionMode & '</connectionMode>' & @CRLF $sXML &= ' <MSM>' & @CRLF $sXML &= ' <security>' & @CRLF $sXML &= ' <authEncryption>' & @CRLF $sXML &= ' <authentication>' & $sAuthentication & '</authentication>' & @CRLF $sXML &= ' <encryption>' $sEncryption & '</encryption>' & @CRLF $sXML &= ' <useOneX>' & $sUseOneX & '</useOneX>' & @CRLF $sXML &= ' </authEncryption>' & @CRLF $sXML &= ' <sharedKey>' & @CRLF $sXML &= ' <keyType>' & $sKeyType & '</keyType>' & @CRLF $sXML &= ' <protected>' & $sProtected & '</protected>' & @CRLF $sXML &= ' <keyMaterial>' & $sPassword & '</keyMaterial>' & @CRLF $sXML &= ' </sharedKey>' & @CRLF $sXML &= ' </security>' & @CRLF $sXML &= ' </MSM>' & @CRLF $sXML &= ' <MacRandomization xmlns="http://www.microsoft.com/networking/WLAN/profile/v3">' & @CRLF $sXML &= ' <enableRandomization>' & $sEnableRandomization & '</enableRandomization>' & @CRLF $sXML &= ' </MacRandomization>' & @CRLF $sXML &= '</WLANProfile>' Local $hOpen = FileOpen($sOutXML, $FO_OVERWRITE) FileWrite($hOpen, $sXML) FileClose($hOpen) ; add profile to cache Local $iPID = Run('netsh wlan add profile filename="' & $sOutXML & '"', $sWkDir, @SW_HIDE, BitOR($STDERR_CHILD, $STDOUT_CHILD)) Local $aRead = _AutNETSH_WLan_STDRead($iPID) If @error Then FileDelete($sOutXML) Return SetError(1, 0, StringRegExpReplace($aRead[1], "(?s)^\s*|\s*$", "")) EndIf Local $sRet = $aRead[0] ; connect to profile $iPID = Run('netsh wlan connect name="' & $sSSID & '"', $sWkDir, @SW_HIDE, BitOR($STDERR_CHILD, $STDOUT_CHILD)) $aRead = _AutNETSH_WLan_STDRead($iPID) If @error Then FileDelete($sOutXML) Return SetError(2, 0, StringRegExpReplace($aRead[1], "(?s)^\s*|\s*$", "")) EndIf FileDelete($sOutXML) $sRet &= " : " & $aRead[0] Return $sRet EndFunc Func _AutNETSH_WLan_ShowNetworks($sWkDir = Default) ; return network array If $sWkDir = Default Or $sWkDir = -1 Then $sWkDir = @UserProfileDir EndIf Local $iPID = Run("netsh wlan show networks", $sWkDir, @SW_HIDE, BitOR($STDERR_CHILD, $STDOUT_CHILD)) Local $aRead = _AutNETSH_WLan_STDRead($iPID) If @error Or Not IsArray($aRead) Then Return SetError(1, @error, StringRegExpReplace($aRead[1], "(?s)^\s*|\s*$", "")) EndIf Local Const $sSSIDRE = "(?si)(SSID\h*\d+\h*\:\h*.+?)(?:\v{3,}|$)" Local $aSSIDs = StringRegExp($aRead[0], $sSSIDRE, $STR_REGEXPARRAYGLOBALMATCH) If @error Or Not IsArray($aSSIDs) Then Return SetError(2, @error, "") EndIf Local $aHeaders = __AutNETSH_WLan_stdoutgetheader($aSSIDs) If @error Then Return SetError(3, @error, "") EndIf Local $aHData = __AutNETSH_WLan_stdoutgethdata($aSSIDs, $aHeaders) If @error Then Return SetError(4, @error, "") EndIf Return $aHData EndFunc ; See RunAs() in help file, may need to sign on as admin acct Func _AutNETSH_WLan_ShowNetworksAsUser($sUserName, $sDomain, $sPassword, $sLogonFlag, $sWkDir = Default) ; return network array If $sWkDir = Default Or $sWkDir = -1 Then $sWkDir = @UserProfileDir EndIf Local $iPID = RunAs($sUserName, $sDomain, $sPassword, $sLogonFlag, _ "netsh wlan show networks", $sWkDir, @SW_HIDE, BitOR($STDERR_CHILD, $STDOUT_CHILD)) Local $aRead = _AutNETSH_WLan_STDRead($iPID) If @error Or Not IsArray($aRead) Then Return SetError(1, 0, StringRegExpReplace($aRead[1], "(?s)^\s*|\s*$", "")) EndIf Local Const $sSSIDRE = "(?si)(SSID\h*\d+\h*\:\h*.+?)(?:\v{3,}|$)" Local $aSSIDs = StringRegExp($aRead[0], $sSSIDRE, $STR_REGEXPARRAYGLOBALMATCH) If @error Or Not IsArray($aSSIDs) Then Return SetError(2, @error, "") EndIf Local $aHeaders = __AutNETSH_WLan_stdoutgetheader($aSSIDs) If @error Then Return SetError(3, @error, "") EndIf Local $aHData = __AutNETSH_WLan_stdoutgethdata($aSSIDs, $aHeaders) If @error Then Return SetError(4, @error, "") EndIf Return $aHData EndFunc Func _AutNETSH_WLan_STDRead($iPID) $iPID = ProcessExists($iPID) If Not $iPID Then Return SetError(1, 0, 0) EndIf Local $sTmp, $sORead, $sOErr While ProcessExists($iPID) $sTmp = StdoutRead($iPID) If @error Then $sOErr = StderrRead($iPID) ExitLoop EndIf $sORead &= $sTmp WEnd ; clean up leading and traling $sORead = StringRegExpReplace($sORead, "(?s)^\s*|\s*$", "") $sOErr = StringRegExpReplace($sOErr, "(?s)^\s*|\s*$", "") Local $aRet[2] = [$sORead, $sOErr] If StringLen($sORead) = 0 Then Return SetError(1, 0, $aRet) EndIf Return $aRet EndFunc Func __AutNETSH_WLan_stdoutgetheader(ByRef $aData) If Not IsArray($aData) Then Return SetError(1, 0, 0) EndIf ; how many heades, some will have more/less based on connection type Local $iExt, $iHeaderCount = 0, $aHeaders For $i = 0 To UBound($aData) - 1 StringRegExpReplace($aData[$i], "(?m)\h+\:", "") $iExt = @extended If $iExt > $iHeaderCount Then $iHeaderCount = $iExt $aHeaders = StringRegExp($aData[$i], "(?m)\h*(.+?)\h+\:", $STR_REGEXPARRAYGLOBALMATCH) If IsArray($aHeaders) Then For $j = 0 To UBound($aHeaders) - 1 If StringInStr($aHeaders[$j], "SSID") Then $aHeaders[$j] = "SSID" ExitLoop EndIf Next EndIf EndIf Next If $iHeaderCount = 0 Then Return SetError(2, 0, 0) EndIf Return SetExtended($iHeaderCount, $aHeaders) EndFunc Func __AutNETSH_WLan_stdoutgethdata(ByRef $aData, ByRef $aHeaders) If Not IsArray($aData) Then Return SetError(1, 0, 0) EndIf If Not IsArray($aHeaders) Then Return SetError(2, 0, 0) EndIf ; [0][n] = headers Local $aRet[UBound($aData) + 1][UBound($aHeaders)] ; fill headers into ret array For $i = 0 To UBound($aHeaders) - 1 $aRet[0][$i] = $aHeaders[$i] ; turn headers into escaped chars $aHeaders[$i] = __AutNETSH_WLan_EscapeDelimiters($aHeaders[$i]) Next Local $aFound, $aLines, $iEnum, $iColCount = 0 ; start at 1, 0 is headers For $i = 0 To UBound($aData) - 1 $iEnum = 0 ; split into individual rows $aLines = StringRegExp($aData[$i], "\h*(.+?)\h*(\v+|$)", $STR_REGEXPARRAYGLOBALMATCH) For $x = 0 To UBound($aLines) - 1 For $j = 0 To UBound($aHeaders) - 1 If StringRegExp($aLines[$x], "(?i)^\h*" & $aHeaders[$j]) Then $aFound = StringRegExp($aLines[$x], "(?mi)\h*" & $aHeaders[$j] & ".*?\:\h*(.+?)\h*$", $STR_REGEXPARRAYGLOBALMATCH) If @error Or Not IsArray($aFound) Then ContinueLoop $aRet[$i + 1][$j] = $aFound[0] $iEnum += 1 ExitLoop EndIf Next Next If $iEnum > 0 Then $iColCount += 1 Next If $iColCount < UBound($aData) Then ; oops EndIf Return $aRet EndFunc Func __AutNETSH_WLan_EscapeDelimiters($sData) Local Const $sRE = "([\\\.\^\$\|\[|\]\(\)\{\}\*\+\?\#])" Local Const $sRep = "\\$1" Return StringRegExpReplace($sData, $sRE, $sRep) EndFunc If you're going to do this across a private network, you may want to look into RunAs(), I have one example function in there with that that you can kind of get the idea from.
    Anyway, I did more than I thought I would for something I can never see myself using... so hope it helps.
    Edit:
    You may need to change this section for enterprise:
    $sXML &= ' <authEncryption>' & @CRLF $sXML &= ' <authentication>WPA2PSK</authentication>' & @CRLF $sXML &= ' <encryption>AES</encryption>' & @CRLF $sXML &= ' <useOneX>false</useOneX>' & @CRLF $sXML &= ' </authEncryption>' & @CRLF I'm to lazy to make something that does it atm.
    Edit2:
    Changed _AutNETSH_WLan_AddConnectionRequest() so you can customize all the xml options if needed.  I'm not 100% on WPA2 Enterprise, but it looks like you can change Authentication = WPA2 and Encryption to TKIP... anyway, really really really done this time 
  23. Like
    SmOke_N got a reaction from VeeDub in Need help adding to a 2D array   
    That's a lot... I'd just use a SQLite database.  It'd be much faster if you're moving through that many files.
    Anyway, you're missing 2 parameters in your _ArrayAdd()

  24. Like
    SmOke_N got a reaction from Ozirys in A bug in Execute()   
    Probably...
    ConsoleWrite( _ExecuteNums("100^2-96^2") & @CRLF) Func _ExecuteNums($vData) Local Const $sRE = "(\d+\h*[\*\\\^]\h*\d+)" Return Execute(StringRegExpReplace($vData, $sRE, "\($1\)")) EndFunc I didn't exclusively test this... you may want to
  25. Thanks
    SmOke_N got a reaction from Chazg in Autoit notifications do not stay in Windows 11 notification centre   
    Some GUIs have timeout features... Just MsgBox() off the top of my head has that option.  But it's an "option", to force it on someone I don't agree with unless it's necessary for an application to continue running.  At minimum there's a 5 second delay option, but max is 5 minutes unfortunately.  Looks like it's time for you to write a notification pop-up logger 💪👍!
×
×
  • Create New...