Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 03/26/2024 in all areas

  1. This UDF provides algorithms for fuzzy string comparison and the associated similarity search in string arrays. It offers functions for character-based comparisons, comparing the phonetics of words and the geometric distance of characters on a keyboard. In this way, typing errors can be recognized, similar-sounding words can be detected and other spellings of words can be included in further processing. The current function list of the UDF: --------- fuzzy array handling: _FS_ArraySearchFuzzy - finds similar entries for a search value in an array _FS_ArrayToPhoneticGroups - groups the values of an array according to their phonetics --------- character-based metrics: _FS_Levenshtein - calculate the levenshtein distance between two strings _FS_OSA - calculate the OSA ("optimal string alignment") between two strings _FS_Hamming - calculate the hamming distance between two strings --------- phonetic metrics: _FS_Soundex_getCode - calculate the soundex code for a given word to represent the pronounciation in english _FS_Soundex_distance - calculate the soundex-pattern for both input values _FS_SoundexGerman_getCode - calculate the modified soundex code for german language for a given word to represent the pronounciation in german _FS_SoundexGerman_distance - calculate the soundexGerman-pattern for both input values _FS_Cologne_getCode - calculate the cologne phonetics code for german language for a given word to represent the pronounciation in german _FS_Cologne_distance - calculate the cologne phonetics distance between both input values --------- key-position based metrics: _FS_Keyboard_GetLayout - return a map with coordinates for the characters for using in _FS_Keyboard_Distance_Chars() _FS_Keyboard_Distance_Chars - calculates the geometric key spacing between two characters on a keyboard _FS_Keyboard_Distance_Strings - calculate the keyboard-distance between two strings >>sourcecode and download on github<<
    2 points
  2. Exactly as you said: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> #include <File.au3> Global $sSourceDir = @DesktopDir Global $sDestinationDir Global $hGUI, $cList, $cAppData, $cCommonFiles, $cExtract Global $aFile = _FileListToArray($sSourceDir, Default, $FLTA_FOLDERS, False) If Not IsArray($aFile) Then Exit $hGUI = GUICreate('Test', 800, 400) $cList = GUICtrlCreateListView('Path', 10, 10, 780, 290, BitOR($LVS_SMALLICON, $WS_DLGFRAME, $LVS_NOCOLUMNHEADER), $LVS_EX_CHECKBOXES) GUICtrlCreateGroup('Destination', 10, 310, 300, 80) $cAppData = GUICtrlCreateRadio('Extract to AppData\Roaming\MyFolder', 20, 330, 260, 20) $cCommonFiles = GUICtrlCreateRadio('Extract to CommonFiles\MyFolder', 20, 360, 260, 20) GUICtrlCreateGroup('', -99, -99, 1, 1) $cExtract = GUICtrlCreateButton('Extract', 650, 350, 140, 40) _GUICtrlListView_BeginUpdate($cList) For $Index = 1 To $aFile[0] If StringLeft($aFile[$Index], 1) = '_' Then ContinueLoop GUICtrlCreateListViewItem($aFile[$Index], $cList) Next _GUICtrlListView_EndUpdate($cList) _GUICtrlListView_SetColumnWidth($cList, 0, 300) GUISetState(@SW_SHOW, $hGUI) While True Switch GUIGetMsg() Case $cExtract If GUICtrlRead($cAppData) = $GUI_CHECKED Then $sDestinationDir = @AppDataDir & '\MyFolder' If GUICtrlRead($cCommonFiles) = $GUI_CHECKED Then $sDestinationDir = @CommonFilesDir & '\MyFolder' If $sDestinationDir Then For $Index = 0 To _GUICtrlListView_GetItemCount($cList) - 1 If _GUICtrlListView_GetItemChecked($cList, $Index) Then DirCopy($sSourceDir & '\' & _GUICtrlListView_GetItemText($cList, $Index), $sDestinationDir, 1) SplashTextOn('', _GUICtrlListView_GetItemText($cList, $Index) & ' successfully extracted !', 300, 100) Sleep(1000) SplashOff() EndIf Next Exit Else MsgBox(0x10, 'Error', 'Please select the extraction directory') EndIf Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd In my opinion would be more nice to display this splash before starting the copy process and close it when it's done without any pause in the script. If _GUICtrlListView_GetItemChecked($cList, $Index) Then SplashTextOn('', 'Extracting ' & _GUICtrlListView_GetItemText($cList, $Index), 300, 100) DirCopy($sSourceDir & '\' & _GUICtrlListView_GetItemText($cList, $Index), $sDestinationDir, 1) SplashOff() EndIf
    1 point
  3. It is the intellectual preoccupation of every programmer
    1 point
  4. #include <GUIConstantsEx.au3> #include <File.au3> ; Change @WindowsDir with whatever path do you want Global $aFile = _FileListToArray(@DesktopDir, Default, $FLTA_FOLDERS, True) If Not IsArray($aFile) Then Exit Global $sDrive, $sDir, $sFileName, $sExtension ; Remove directories that starts with an underscore Global $sFiles = '' For $Index = 1 To $aFile[0] _PathSplit($aFile[$Index], $sDrive, $sDir, $sFileName, $sExtension) $sFiles &= (StringLeft($sFileName, 1) <> '_' ? $aFile[$Index] & '|' : '') Next $aFile = StringSplit(StringTrimRight($sFiles, 1), '|') Global $sPath Global $iFolders = $aFile[0] Global $asFolder[$iFolders], $asPath[$iFolders], $acCtrl[$iFolders] Global $iCols = Int($iFolders / 10) + (Mod($iFolders, 10) ? 1 : 0) Global $iColWidth = 120 Global $iWidth = ($iCols * $iColWidth < 500 ? 500 : $iCols * $iColWidth) For $Index = 0 To $iFolders - 1 _PathSplit($aFile[$Index + 1], $sDrive, $sDir, $sFileName, $sExtension) $asFolder[$Index] = $sFileName $asPath[$Index] = $aFile[$Index + 1] ; This is kinda redundant but used for the sake of symmetry with the previous example Next $hGUI = GUICreate('Test', $iWidth, 400) For $Index = 0 To $iFolders - 1 $acCtrl[$Index] = GUICtrlCreateCheckbox($asFolder[$Index], Int($Index / 10) * 120 + 10, Mod($Index, 10) * 30 + 10, $iColWidth - 20, 20) Next GUICtrlCreateGroup('Destination', 10, 310, 300, 80) $cAppData = GUICtrlCreateRadio('Extract to AppData\Roaming\MyFolder', 20, 330, 260, 20) $cCommonFiles = GUICtrlCreateRadio('Extract to CommonFiles\MyFolder', 20, 360, 260, 20) GUICtrlCreateGroup('', -99, -99, 1, 1) $cExtract = GUICtrlCreateButton('Extract', $iWidth - 150, 350, 140, 40) GUISetState(@SW_SHOW, $hGUI) While True Switch GUIGetMsg() Case $cExtract If GUICtrlRead($cAppData) = $GUI_CHECKED Then $sPath = @AppDataDir & '\MyFolder' If GUICtrlRead($cCommonFiles) = $GUI_CHECKED Then $sPath = @CommonFilesDir & '\MyFolder' If $sPath Then For $Index = 0 To $iFolders - 1 If GUICtrlRead($acCtrl[$Index]) = $GUI_CHECKED Then ; ConsoleWrite($asPath[$Index] & ' --->>> ' & $sPath & @CRLF) DirCopy($asPath[$Index], $sPath, 1) EndIf Next Else MsgBox(0x10, 'Error', 'Please select the extraction directory') EndIf Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd This would be a more elegant solution using a listview. This can be suitable if you have many items to display. #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> #include <File.au3> Global $sSourceDir = @DesktopDir Global $sDestinationDir Global $hGUI, $cList, $cAppData, $cCommonFiles, $cExtract Global $aFile = _FileListToArray($sSourceDir, Default, $FLTA_FOLDERS, False) If Not IsArray($aFile) Then Exit $hGUI = GUICreate('Test', 800, 400) $cList = GUICtrlCreateListView('Path', 10, 10, 780, 290, BitOR($LVS_SMALLICON, $WS_DLGFRAME, $LVS_NOCOLUMNHEADER), $LVS_EX_CHECKBOXES) GUICtrlCreateGroup('Destination', 10, 310, 300, 80) $cAppData = GUICtrlCreateRadio('Extract to AppData\Roaming\MyFolder', 20, 330, 260, 20) $cCommonFiles = GUICtrlCreateRadio('Extract to CommonFiles\MyFolder', 20, 360, 260, 20) GUICtrlCreateGroup('', -99, -99, 1, 1) $cExtract = GUICtrlCreateButton('Extract', 650, 350, 140, 40) _GUICtrlListView_BeginUpdate($cList) For $Index = 1 To $aFile[0] If StringLeft($aFile[$Index], 1) = '_' Then ContinueLoop GUICtrlCreateListViewItem($aFile[$Index], $cList) Next _GUICtrlListView_EndUpdate($cList) _GUICtrlListView_SetColumnWidth($cList, 0, 300) GUISetState(@SW_SHOW, $hGUI) While True Switch GUIGetMsg() Case $cExtract If GUICtrlRead($cAppData) = $GUI_CHECKED Then $sDestinationDir = @AppDataDir & '\MyFolder' If GUICtrlRead($cCommonFiles) = $GUI_CHECKED Then $sDestinationDir = @CommonFilesDir & '\MyFolder' If $sDestinationDir Then For $Index = 0 To _GUICtrlListView_GetItemCount($cList) - 1 If _GUICtrlListView_GetItemChecked($cList, $Index) Then ; ConsoleWrite($sSourceDir & '\' & _GUICtrlListView_GetItemText($cList, $Index) & ' --->>> ' & $sDestinationDir & @CRLF) DirCopy($sSourceDir & '\' & _GUICtrlListView_GetItemText($cList, $Index), $sDestinationDir, 1) EndIf Next Else MsgBox(0x10, 'Error', 'Please select the extraction directory') EndIf Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd
    1 point
  5. Here is a real case of the previous example without fake data. It will display all directories from windows: #include <GUIConstantsEx.au3> #include <File.au3> ; Change @WindowsDir with whatever path do you want Global $aFile = _FileListToArray(@WindowsDir, Default, $FLTA_FOLDERS, True) If Not IsArray($aFile) Then Exit Global $sPath Global $iFolders = $aFile[0] Global $asFolder[$iFolders], $asPath[$iFolders], $acCtrl[$iFolders] Global $iCols = Int($iFolders / 10) + (Mod($iFolders, 10) ? 1 : 0) Global $iColWidth = 120 Global $iWidth = ($iCols * $iColWidth < 500 ? 500 : $iCols * $iColWidth) Global $sDrive, $sDir, $sFileName, $sExtension For $Index = 0 To $iFolders - 1 _PathSplit($aFile[$Index + 1], $sDrive, $sDir, $sFileName, $sExtension) $asFolder[$Index] = $sFileName $asPath[$Index] = $aFile[$Index + 1] ; This is kinda redundant but used for the sake of symmetry with the previous example Next $hGUI = GUICreate('Test', $iWidth, 400) For $Index = 0 To $iFolders - 1 $acCtrl[$Index] = GUICtrlCreateCheckbox($asFolder[$Index], Int($Index / 10) * 120 + 10, Mod($Index, 10) * 30 + 10, $iColWidth - 20, 20) Next GUICtrlCreateGroup('Destination', 10, 310, 300, 80) $cAppData = GUICtrlCreateRadio('Extract to AppData\Roaming\MyFolder', 20, 330, 260, 20) $cCommonFiles = GUICtrlCreateRadio('Extract to CommonFiles\MyFolder', 20, 360, 260, 20) GUICtrlCreateGroup('', -99, -99, 1, 1) $cExtract = GUICtrlCreateButton('Extract', $iWidth - 150, 350, 140, 40) GUISetState(@SW_SHOW, $hGUI) While True Switch GUIGetMsg() Case $cExtract If GUICtrlRead($cAppData) = $GUI_CHECKED Then $sPath = @AppDataDir & '\MyFolder' If GUICtrlRead($cCommonFiles) = $GUI_CHECKED Then $sPath = @CommonFilesDir & '\MyFolder' If $sPath Then For $Index = 0 To $iFolders - 1 If GUICtrlRead($acCtrl[$Index]) = $GUI_CHECKED Then ConsoleWrite($asPath[$Index] & ' --->>> ' & $sPath & @CRLF) ;~ DirCopy($asPath[$Index], $sPath, 1) EndIf Next Else MsgBox(0x10, 'Error', 'Please select the extraction directory') EndIf Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd PS: don't run it with DirCopy() uncommented because it will copy the content of windows directory to selected destination. If you have way more items than could fit nicely in your window you might consider using a listview with checkboxes.
    1 point
  6. Try to modify the script to fit your needs and if you need further help just let me know more details. Edit: made an example for you with dynamic number of folders #include <GUIConstantsEx.au3> Global $sPath Global $iFolders = 100 ; Change this as you want Global $asFolder[$iFolders], $asPath[$iFolders], $acCtrl[$iFolders] Global $iCols = Int($iFolders / 10) + (Mod($iFolders, 10) ? 1 : 0) Global $iColWidth = 120 Global $iWidth = ($iCols * $iColWidth < 500 ? 500 : $iCols * $iColWidth) ; Generate some fake data but this can be read from a file, a database or other methods For $Index = 0 To $iFolders - 1 $asFolder[$Index] = 'Folder ' & ($Index + 1) $asPath[$Index] = @ScriptDir & '\Folder ' & ($Index + 1) Next $hGUI = GUICreate('Test', $iWidth, 400) For $Index = 0 To $iFolders - 1 $acCtrl[$Index] = GUICtrlCreateCheckbox($asFolder[$Index], Int($Index / 10) * 120 + 10, Mod($Index, 10) * 30 + 10, $iColWidth - 20, 20) Next GUICtrlCreateGroup('Destination', 10, 310, 300, 80) $cAppData = GUICtrlCreateRadio('Extract to AppData\Roaming\MyFolder', 20, 330, 260, 20) $cCommonFiles = GUICtrlCreateRadio('Extract to CommonFiles\MyFolder', 20, 360, 260, 20) GUICtrlCreateGroup('', -99, -99, 1, 1) $cExtract = GUICtrlCreateButton('Extract', $iWidth - 150, 350, 140, 40) GUISetState(@SW_SHOW, $hGUI) While True Switch GUIGetMsg() Case $cExtract If GUICtrlRead($cAppData) = $GUI_CHECKED Then $sPath = @AppDataDir & '\MyFolder' If GUICtrlRead($cCommonFiles) = $GUI_CHECKED Then $sPath = @CommonFilesDir & '\MyFolder' If $sPath Then For $Index = 0 To $iFolders - 1 If GUICtrlRead($acCtrl[$Index]) = $GUI_CHECKED Then ConsoleWrite($asFolder[$Index] & ' --->>> ' & $sPath & @CRLF) ;~ DirCopy($asPath[$Index], $sPath, 1) EndIf Next Else MsgBox(0x10, 'Error', 'Please select the extraction directory') EndIf Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd
    1 point
  7. #RequireAdmin #include <GUIConstants.au3> #include <GUIConstantsEx.au3> #include <ButtonConstants.au3> ;======================================= Global $S01, $S02, $S03, $S04, $S05, $S06, $RDD, $CDD GUICreate("Small Test:", 400, 300) $Mylogo = @ScriptDir & "\logo.bmp" $logo = GUICtrlCreatePic($Mylogo, 0, 0, 400, 65) GUISetBkColor(0x00dadacc) GUISetFont(9, 900) $Go = GUICtrlCreateButton("Go", 330, 260, 60, 25) GUICtrlCreateGraphic(5, 75, 390, 2, $SS_BLACKRECT) GUICtrlCreateGraphic(5, 240, 390, 2, $SS_BLACKRECT) $S01 = GUICtrlCreateCheckbox("SomeName1", 10, 90, 300, 20) $S02 = GUICtrlCreateCheckbox("SomeName2", 10, 110, 300, 20) $S03 = GUICtrlCreateCheckbox("SomeName3", 10, 130, 300, 20) $S04 = GUICtrlCreateCheckbox("SomeName4", 10, 150, 300, 20) $S05 = GUICtrlCreateCheckbox("SomeName5", 10, 170, 300, 20) $S06 = GUICtrlCreateCheckbox("SomeName6", 10, 190, 300, 20) $RDD = GUICtrlCreateRadio("Extract to AppData\Roaming\MyFolder", 10, 250, 280, 20) GUICtrlSetState($RDD, $GUI_CHECKED) $CDD = GUICtrlCreateRadio("Extract to CommonFiles\MyFolder", 10, 270, 280, 20) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Go ;====================== ; If ($RDD GUICtrlCreateRadio) is checked extract to AppData\Roaming\MyFolder ; If ($CDD GUICtrlCreateRadio) is checked extract to Common Files\MyFolder ;====================== If GUICtrlRead($RDD) = $GUI_CHECKED Then $sPath = @AppDataDir If GUICtrlRead($CDD) = $GUI_CHECKED Then $sPath = @CommonFilesDir If GUICtrlRead($S01) = $GUI_CHECKED Then DirCopy(@ScriptDir & "\Folder-1", $sPath & "\" & GUICtrlRead($S01, 1), 1) If GUICtrlRead($S02) = $GUI_CHECKED Then DirCopy(@ScriptDir & "\Folder-2", $sPath & "\" & GUICtrlRead($S02, 1), 1) If GUICtrlRead($S03) = $GUI_CHECKED Then DirCopy(@ScriptDir & "\Folder-3", $sPath & "\" & GUICtrlRead($S03, 1), 1) If GUICtrlRead($S04) = $GUI_CHECKED Then DirCopy(@ScriptDir & "\Folder-4", $sPath & "\" & GUICtrlRead($S04, 1), 1) If GUICtrlRead($S05) = $GUI_CHECKED Then DirCopy(@ScriptDir & "\Folder-5", $sPath & "\" & GUICtrlRead($S04, 1), 1) If GUICtrlRead($S06) = $GUI_CHECKED Then DirCopy(@ScriptDir & "\Folder-6", $sPath & "\" & GUICtrlRead($S06, 1), 1) ExitLoop EndSelect WEnd Exit
    1 point
  8. You can read this data from a file.
    1 point
  9. You could use ternary (single line) : If GuiCtrlRead($S01) = 1 Then DirCopy(@ScriptDir & "\Folder-1", (GuiCtrlRead($RDD) = 1 ? @AppDataDir : @CommonFilesDir) & "\MyFolder", 1)
    1 point
  10. put GUIStartGroup() above every radio
    1 point
  11. Both of you need to either learn to scroll or walk away from the thread; the bickering is tiresome already.
    1 point
  12. Here is the CSS, I'd like your opinion on whether I matched font sizing and link positioning. Some things to note: This will break the original chm display using the Object, i.e: I left all the px values in the CSS and just commented them out, and added "/*@*/" after all my ex values, it will need to be cleaned up when we're done debugging. I can do that if you like/when you want. I didn't remove the empty spaces I mentioned in my earlier post on page (2?), but that would be a simple change in the CSS later if you want. I am attaching the Msgbox htm I modified, I left in "<META HTTP-EQUIV="Content-Type" CONTENT="text-html;charset=UTF-8">" till you get done your testing. I created the open link as follows, as I don't know how to make it the same as the current copy to clipboard link: I only changed between "hhctrlA.Click()" and "hhctrlB.Click()" for Example 1 & 2. I left all old lines in the htm file, but commented them out: And for the class, as mentioned, I added above the open script link: I didn't modify the other htm file in your test chm, but I am including the chm for easy viewing. Probably forgetting something. Edit: The only reason now to add/ change to using emulation like we tried, "<meta http-equiv="X-UA-Compatible" content="IE=edge" /> " or "<meta http-equiv="X-UA-Compatible" content="IE=IE11" /> " etc would be to allow users to use more/ newer CSS features, which, at least from my testing, won't generally work (for example, the @media example I posted above). But from the looks of it, using the emulation is seeming to cause oddities, such as the one you noticed with the missing border. So probably not worth it. Edit2: I had a couple wrong values: Open Link AutoIt.zip
    1 point
  13. #include <WinAPISys.au3> Global $hEventProc = DllCallbackRegister(_EventProc, 'none', 'ptr;dword;hwnd;long;long;dword;dword') OnAutoItExitRegister(OnAutoItExit) HotKeySet("{ESC}", Terminate) Local $iPID = Run("Notepad") Global $hEventHook = _WinAPI_SetWinEventHook($EVENT_SYSTEM_DIALOGSTART, $EVENT_SYSTEM_DIALOGSTART, DllCallbackGetPtr($hEventProc), $iPID) Local $hWnd = WinWaitActive("[CLASS:Notepad]") ControlSend($hWnd, "", "Edit1", "Test") ControlSend($hWnd, "", "", "!{F4}") ; simulate a msgbox While 1 Sleep(1000) WEnd Func Terminate() Exit EndFunc ;==>Terminate Func OnAutoItExit() _WinAPI_UnhookWinEvent($hEventHook) DllCallbackFree($hEventProc) EndFunc ;==>OnAutoItExit Func _EventProc($hEventHook, $iEvent, $hWnd, $iObjectID, $iChildID, $iThreadId, $iEventTime) WinMove($hWnd, "", @DesktopWidth, @DesktopHeight) WinKill($hWnd) ConsoleWrite("Closed" & @CRLF) EndFunc ;==>_EventProc
    1 point
  14. I am trying to validate input to make sure it follows Active Directory password rules, except it should have 10 char. Technically, this should come back as false but it seems to be validating as true... $Password = "Pass1" $result = StringRegExp($Password,"^(?=.*?[a-z])(?=.*?[A-Z])(?=.*?[0-9])(?=.*?[#!@$%^&*()\-_+={}[\]|\\:;<>,.?\/]).{10,16}$") if @Error then Msgbox(0,"error level",@Error) else Msgbox(0,"test",$result) EndIf This is a breakdown of the Regex I am using... ^ # anchors to start of string (?=.*?[a-z]) # lookahead for lowercase (?=.*?[A-Z]) # lookahead for uppercase (?=.*?[0-9]) # lookahead for numbers (?=.*?[#!@$%^&*()\-_+={}[\\]|\:;<>,.?\/]) # lookahead for special characters .{8,14} # the actual capture, also sets boundaries for 8-14 $ # anchors to end of string Where did I go wrong? This should tell me that Pass1 is no good.
    1 point
  15. Hi, I thought i'd share a small script that scans your Windows Eventlog and generates a blacklist/firewall block rule of IPs that tries to hammer your RDP connection with wrong credentials. Yes, i know it's not best practice to have RDP open to the internet but sometimes it's just more practical. I havn't had time to create a loop in the script itself but you can run it in windows scheduler with a 10 minute recurrence. This is a quick and dirty solution and for those that like the idea, please feel free to improve/tidy the code. #RequireAdmin #include <Date.au3> #include <array.au3> #include <File.au3> Global $IpListFile = @scriptdir &"\RdpBlockIP.txt" Global $LogFile = @scriptdir &"\RdpBlockLog.txt" Global $EventlogOutput = @scriptdir &"\EventlogOutput.xml" Global $FailedAttepts = IniRead(@scriptdir &"\RdpBlock.ini", "Settings", "FailedAttempts", "3") Global $WithinMinutes = IniRead(@scriptdir &"\RdpBlock.ini", "Settings", "WithinMinutes", "720") Global $Whitelist = IniRead(@scriptdir &"\RdpBlock.ini", "Settings", "Whitelist", "192.168.0") Global $LogArray[0][2] Global $BlacklistArray[0] RunWait(@ComSpec & " /c " & 'wevtutil qe "Microsoft-Windows-RemoteDesktopServices-RdpCoreTS/Operational" "/q:*[System [(EventID=140)]]" /c:2000 /rd:true /f:xml>'&$EventlogOutput , "", @SW_HIDE) $FileArray = FileReadToArray ( $EventlogOutput ) FileDelete($EventlogOutput) ;Fill $LogArray with last hours logs $FirstStamp = 0 For $i = 0 to UBound($FileArray) -1 $LineArray = StringSplit ( $FileArray[$i], ">" ) $IP = StringTrimRight($LineArray[29], 6) $StampArray = StringSplit($LineArray[16], "'") $StampArray = StringSplit($StampArray[2], "T") $Date = $StampArray[1] $TimeArray = StringSplit($StampArray[2], ".") $Time = $TimeArray[1] $sFill = $IP&"|"&$Date&" "&$Time If $FirstStamp = 0 then $FirstStamp = $Date&" "&$Time If _DateDiff('n', $Date&" "&$Time, $FirstStamp) = $WithinMinutes then ExitLoop _ArrayAdd($LogArray,$sFill) Next For $i = 0 to Ubound($LogArray)-1 $SarchIP = _ArrayFindAll ( $LogArray, $LogArray[$i][0]) If StringInStr($Whitelist, $LogArray[$i][0]) Then Else If Ubound($SarchIP) >= $FailedAttepts Then _ArrayAdd($BlacklistArray, $LogArray[$i][0]) EndIf Next ;Unless first run, include IPs from file If FileExists ($IpListFile) then ;Concatenate old with new array of IPs and delete duplicates $FileArray = FileReadToArray ( $IpListFile ) $FileIpCount = Ubound($FileArray) _ArrayConcatenate ( $FileArray, $BlacklistArray) $IpUniqueArray = _ArrayUnique ( $FileArray) If $IpUniqueArray[0] - $FileIpCount > 0 then _FileWriteLog($LogFile, 'Adding '& $IpUniqueArray[0] - $FileIpCount & ' addresses to current list ('&$FileIpCount&'), now '&$IpUniqueArray[0]&' in total.' ) ;Write IP list to file _ArraySort ($IpUniqueArray, 0, 1, $IpUniqueArray[0]) $IpList = _ArrayExtract ( $IpUniqueArray , 1 , $IpUniqueArray[0]) FileDelete($IpListFile) _FileWriteFromArray($IpListFile, $IpList) Else $IpUniqueArray = _ArrayUnique ($BlacklistArray) _ArraySort ($IpUniqueArray, 0, 1, $IpUniqueArray[0]) _FileWriteLog($LogFile, 'Adding '& $IpUniqueArray[0]& ' addresses to list of RDP blacklist.') $IpList = _ArrayExtract ( $IpUniqueArray , 1 , $IpUniqueArray[0]) _FileWriteFromArray($IpListFile, $IpList) EndIf ;Delete old FW rules RunWait(@ComSpec & " /c " & 'netsh advfirewall firewall show rule status=enabled name=all | find "RdpBlacklist" > '&@ScriptDir&'\output.txt' , "", @SW_HIDE) $Output = FileRead ( @ScriptDir&'\output.txt') FileDelete(@ScriptDir&'\output.txt') $Output = StringReplace($Output, "Rule Name:", "") $Output = StringReplace($Output, " ", "") $RulesArray = StringSplit($Output, @LF) For $d = 1 to $RulesArray[0]-1 RunWait(@ComSpec & " /c " & 'netsh advfirewall firewall delete rule name='&$RulesArray[$d] , "", @SW_HIDE) Next ;Create FW rules with max 100 IPs per rule (native limit) For $i = 1 to $IpUniqueArray[0] Step 100 If $i+99 > $IpUniqueArray[0] then $SplitIpArray = _ArrayExtract ( $IpUniqueArray , $i, $IpUniqueArray[0] ) $IpString = _ArrayToString($SplitIpArray, ",") If $IpString > "" then RunWait(@ComSpec & " /c " & 'netsh advfirewall firewall add rule name="RdpBlacklist'&StringFormat("%04d", $i)&'-'&StringFormat("%04d", $IpUniqueArray[0])&'" dir=in interface=any action=block remoteip='&$IpString, "", @SW_HIDE) Else $SplitIpArray = _ArrayExtract ( $IpUniqueArray , $i, $i+99) $IpString = _ArrayToString($SplitIpArray, ",") If $IpString > "" then RunWait(@ComSpec & " /c " & 'netsh advfirewall firewall add rule name="RdpBlacklist'&StringFormat("%04d", $i)&'-'&StringFormat("%04d", $i+99)&'" dir=in interface=any action=block remoteip='&$IpString, "", @SW_HIDE) EndIf Next The script operates with a simple ini file called RdpBlock.ini that you can create yourself or just download the attached one. [Settings] FailedAttempts=5 WithinMinutes=10 Whitelist= RdpBlock.ini
    1 point
  16. Homes32

    WIMGAPI UDF

    A UDF for manipulating Windows Image Files (.wim) without ImageX.exe This UDF allows you to use the Windows Imaging API directly (wimgapi.dll) so you don't have to use a command line program such as ImageX. Benefits are wimgapi.dll is shipped with windows 7 so users don't have to download the 1gb+ AIK to manage wim files. The UDF also allows you to utilize callback functions so you can show detailed progress info to your users. wimfltr.sys/wimmount.sys required for mount/unmount only. working with both 32 and 64 bit builds. its pretty well documented but you should still read the MS Imaging API documentation and be familiar how wimgapi.dll works to get the most out of this UDF. functions marked with an (*) are only available with newer versions of wimgapi.dll Functions Included: _WIM_ApplyImage _WIM_CaptureImage _WIM_CloseHandle _WIM_CreateFile _WIM_DeleteImage _WIM_DeleteImageMounts * _WIM_ExportImage _WIM_ExtractImagePath * _WIM_GetImageAttributes _WIM_GetImageCount _WIM_GetImageInformation _WIM_LoadImage _WIM_MountImage _WIM_RegisterLogFile * _WIM_RegisterMessageCallback _WIM_RemountImage * _WIM_SetBootImage _WIM_SetImageInformation _WIM_SetReferenceFile _WIM_SetTemporaryPath _WIM_Shutdown _WIM_Startup _WIM_UnMountImage _WIM_UnRegisterLogFile * _WIM_UnregisterMessageCallback have fun! Homes32 Sample Usage #include <Wimgapi.au3> ; functions for WIM Global $swimfile, $hWim, $hImage, $filepath, $Percent, $rTime, $pCallBack Global $gsWimDLL = @SystemDir & "wimgapi.dll" ; path to wimgapi.dll $ProgramName = "WIM Demo" ; Fire up wimgapi.dll $aResult = _WIM_Startup() If @error = 2 Then MsgBox(16, $ProgramName, "Error loading library: " & "(" & $aResult & "," & @error & ", " & $gsWimDLL & ")" & @CRLF & @CRLF & "The file could not be found.") Exit (2) ElseIf @error = 1 Then MsgBox(16, $ProgramName, "Error loading library: " & "(" & $aResult & "," & @error & ", " & $gsWimDLL & ")" & @CRLF & @CRLF & "Wrong DLL. Make sure you are using the right arch (x86/x64)") Exit (254) EndIf ; your code here ; ex. ; Capture("C:toolz", "c:test.wim", "My Test IMG", "Test Desc", 1) ; Cleanup() ; Apply ;----------------------------- Func Apply($sWimFile, $iImageIndex, $sTarget) ProgressOn('Apply', '', '', -1, -1, 19) ; Register callbacks so we get progress information for the capture process. ; WARNING: This does not work very well with Apply do to the way autoit handles callbacks. ; See the following post for more info: ; http://www.autoitscript.com/forum/topic/127075-wimgapi-udf/page__view__findpost__p__917049 $pCallBack = DllCallbackRegister('CallBack', 'int', 'dword;WPARAM;LPARAM;dword') _WIM_RegisterMessageCallback(0, DllCallbackGetPtr($pCallBack), 0) ; load .wim file with read access $hWim = _WIM_CreateFile($sWimFile, $WIM_GENERIC_READ, $WIM_OPEN_EXISTING, 0, 0, 0) If $hWim = 0 Then MsgBox(48, $ProgramName, "Error: Failed to load image. (" & $hWim & "," & @error & "," & @extended & ")") Cleanup() Exit (252) EndIf ; set our temp path $aResult = _WIM_SetTemporaryPath($hWim, $sTarget) ; load the image index $hImage = _WIM_LoadImage($hWim, $iImageIndex) ; Apply the image $aResult = _WIM_ApplyImage($hImage, $sTarget) If $aResult = 0 Then MsgBox(48, $ProgramName, "Error: Failed to apply image. Make sure your path exists! (" & $aResult & "," & @error & "," & @extended & ")") Cleanup() ProgressOff() EndFunc ; Mount ;----------------------------- Func Mount($sMountPath, $sWimFile, $iImageIndex, $RW) $aResult = _WIM_MountImage($sMountPath, $sWimFile, $iImageIndex, $RW) If $aResult = 0 Then MsgBox(48, $ProgramName, "Mount Error: (" & $aResult & "," & @error & "," & @extended & ")") Cleanup() Exit (253) ; mount error EndIf Cleanup() EndFunc ; UnMount ;----------------------------- Func UnMount($sMountPath, $iCommit) $aResult = _WIM_UnMountImage($sMountPath, 0, 0, $iCommit) If $aResult = 0 Then MsgBox(48, $ProgramName, "UnMount Error: (" & $aResult & "," & @error & "," & @extended & ")") Cleanup() Exit (254) ; Unmount error EndIf Cleanup() EndFunc ; GetInfo ;----------------------------- Func GetInfo($sWimFile) ; load .wim file with read access $hWim = _WIM_CreateFile($sWimFile, $WIM_GENERIC_READ, $WIM_OPEN_EXISTING, 0, 0, 0) If $hWim = 0 Then MsgBox(48, $ProgramName, "Error: Failed to load image. (" & $hWim & "," & @error & "," & @extended & ")") Cleanup() Exit (252) EndIf ; set our temp path $aResult = _WIM_SetTemporaryPath($hWim, @TempDir) ; read wim attributes $aWimAttribs = _WIM_GetImageAttributes($hWim) ; read info from the image $aXML = _WIM_GetImageInformation($hWim) ; Cleanup any open handles Cleanup() ; make our output pretty Switch $aWimAttribs[4] Case $WIM_COMPRESS_NONE $aWimAttribs[4] = "NONE" Case $WIM_COMPRESS_XPRESS $aWimAttribs[4] = "XPRESS" Case $WIM_COMPRESS_LZX $aWimAttribs[4] = "LZX" EndSwitch Local $outFile = @ScriptDir & "wiminfo.txt" If FileExists($outFile) Then FileDelete($outFile) FileWrite($outFile, @CRLF & $ProgramName & @CRLF & @CRLF & @CRLF & @CRLF & _ "WIM Information:" & @CRLF & _ "----------------" & @CRLF & _ "Wim Path: : " & $aWimAttribs[1] & @CRLF & _ "GUID : " & $aWimAttribs[2] & @CRLF & _ "Image Count: " & $aWimAttribs[3] & @CRLF & _ "Compression: " & $aWimAttribs[4] & @CRLF & _ "Part Number: " & $aWimAttribs[5] & "/" & $aWimAttribs[6] & @CRLF & _ "Boot Index : " & $aWimAttribs[7] & @CRLF & _ "Attributes : " & $aWimAttribs[8] & @CRLF & @CRLF & @CRLF & _ "Available Image Choices:" & @CRLF & _ "------------------------" & @CRLF & _ $aXML[1]) EndFunc ;==>GetInfo ; Extract ;----------------------------- Func Extract($sWimFile, $iImageIndex, $sFilePath, $sExtractTo) ; load .wim file with read access $hWim = _WIM_CreateFile($sWimFile, $WIM_GENERIC_READ, $WIM_OPEN_EXISTING, 0, 0, 0) If $hWim = 0 Then MsgBox(48, $ProgramName, "Error: Failed to load image. (" & $hWim & "," & @error & "," & @extended & ")") Cleanup() Exit (252) EndIf ; set our temp path $aResult = _WIM_SetTemporaryPath($hWim, @TempDir) ; load the image index $hImage = _WIM_LoadImage($hWim, $iImageIndex) ; extract the file $aResult = _WIM_ExtractImagePath($hImage, $sFilePath, $sExtractTo) If $aResult = 0 Then MsgBox(48, $ProgramName, "Error: Failed to extract from image. Make sure your path exists! (" & $aResult & "," & @error & "," & @extended & ")") Cleanup() EndFunc ; Capture ;----------------------------- Func Capture($Path, $sWimFile, $sImageName, $sImageDesc, $Compress) ProgressOn('Capture', '', '', -1, -1, 19) ; Register callbacks so we get progress information for the capture process. $pCallBack = DllCallbackRegister('CallBack', 'int', 'dword;WPARAM;LPARAM;dword') _WIM_RegisterMessageCallback(0, DllCallbackGetPtr($pCallBack), 0) ; first we need to create a blank .wim file with write access and our compression options $hWim = _WIM_CreateFile($sWimFile, $WIM_GENERIC_WRITE, $WIM_CREATE_ALWAYS, 0, $Compress, 0) If $hWim = 0 Then MsgBox(48, $ProgramName, "Error: Failed to create image. (" & $hWim & "," & @error & "," & @extended & ")") Cleanup() Exit (252) ; image create failed EndIf ; set our temp path $aResult = _WIM_SetTemporaryPath($hWim, @TempDir) ; start the image capture!!! $hImage = _WIM_CaptureImage($hWim, $Path, 0) If $hImage = 0 Then MsgBox(48, $ProgramName, "Error: Failed to capture image. (" & $hImage & "," & @error & "," & @extended & ")") Cleanup() Exit (251) ; image capture failed EndIf ; add our name and description to the XML data - ChrW(65279) is the BOM $sXML = ChrW(65279) & "<IMAGE><NAME>" & $sImageName & "</NAME><DESCRIPTION>" & $sImageDesc & "</DESCRIPTION></IMAGE>" _WIM_SetImageInformation($hImage, $sXML) _WIM_SetBootImage($hWim, 1) Cleanup() ; free resources ProgressOff() EndFunc ;==>Capture ; ================================================================================================================== ; Function: CallBack ; Description: Very Basic Sample Callback function for capture progress ; Usage: CallBack($msgId, $param1, $param2, $b) ; Author: Homes32 ; ================================================================================================================== Func CallBack($msgId, $param1, $param2, $unused) Switch $msgId Case $WIM_MSG_PROGRESS ; get progress % and time remaining $Percent = $param1 If $param2 = 0 Then $rTime = "" Else $rTime = StringFormat('Remaining: %i sec.', $param2 / 1000) EndIf Case $WIM_MSG_PROCESS ; get the file name being processed $Struct = DllStructCreate("ushort[1024]", $param1) $sFilePath = "" $i = 1 While 1 $Tmp = DllStructGetData($Struct, 1, $i) If $Tmp = 0 Then ExitLoop $sFilePath &= ChrW($Tmp) $i += 1 WEnd EndSwitch ProgressSet($Percent, StringFormat('%3i%% completed. %snn %s', $Percent, $rTime, $filePath), 'Capture ' & $sWimFile) Return $WIM_MSG_SUCCESS EndFunc ;==>CallBack Func Cleanup() ; Cleanup any open handles If $hImage Then _WIM_CloseHandle($hImage) If $hWim Then _WIM_CloseHandle($hWim) If $pCallBack Then ; Cleanup our callbacks $aResult = _WIM_UnregisterMessageCallback(0, DllCallbackGetPtr($pCallBack)) DllCallbackFree($pCallBack) EndIf _WIM_Shutdown() ; shutdown wimgapi.dll EndFunc ;==>Cleanup History v1 3-30-2011 * 1st release v2 4-4-2011 * cleaned up the documention * added the following functions _WIM_DeleteImage _WIM_DeleteImageMounts _WIM_ExportImage _WIM_RemountImage _WIM_SetReferenceFile v3 9-19-2011 * Fixed Access Violation crash in _WIM_GetImageInformation Previous Downloads: 312 WimgapiUDF.zip
    1 point
  17. Rawox, This should get you started. At the moment it gives you all the windows (i.e including controls) but as it gives you the class info as well I will leave sorting that out as an exercise for the student: #include <WinAPI.au3> HotKeySet("{ESC}", "On_Exit") Func On_Exit() Exit EndFunc $hCurr_HhWnd = 0 While 1 If @AutoItX64 Then Local $tPoint = DllStructCreate("int X;int Y") DllStructSetData ( $tPoint, "X", MouseGetPos(0)) DllStructSetData ( $tPoint, "Y", MouseGetPos(1)) Local $tPoint64 = DllStructCreate("int64", DllStructGetPtr($tPoint)) Local $aHwnd = DllCall("user32.dll", "hwnd", "WindowFromPoint", "int64", DllStructGetData($tPoint64, 1)) Else Local $aHwnd = DllCall("user32.dll", "hwnd", "WindowFromPoint", "uint", MouseGetPos(0), "uint", MouseGetPos(1)) EndIf If $aHwnd[0] <> $hCurr_HhWnd Then ConsoleWrite($aHwnd[0] & " - " & _WinAPI_GetClassName($aHwnd[0]) & @CRLF) $hCurr_HhWnd = $aHwnd[0] EndIf WEnd M23
    1 point
  18. StringReplace($strings,@CRLF&@CRLF,"")
    1 point
×
×
  • Create New...