Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 09/23/2016 in all areas

  1. funkey

    Binary Data for UDP

    Global $tData = DllStructCreate("byte myTxData[54]") Global $tMeaningfulStruct = DllStructCreate("byte flags[6];byte data[6]", DllStructGetPtr($tData)) ; point to the data struct DllStructSetData($tMeaningfulStruct, "flags", _SetBit(0, 0), 2) ; set bit 0 of second flag byte DllStructSetData($tMeaningfulStruct, "flags", _SetBit(0, 1), 3) ; set bit 1 of third flag byte DllStructSetData($tMeaningfulStruct, "data", 0xff, 2) ; set 0xff to second data byte Global $bData = DllStructGetData($tData, "myTxData") ConsoleWrite($bData & @CRLF) Func _SetBit($bVal, $iPos) Return BitOR($bVal, 2^$iPos) EndFunc
    2 points
  2. I wrote this very simple functions to parse command line arguments. It can get: Simple key/value Example. The following code: #include "cmdline.au3" MsgBox(0, _CmdLine_Get('color')) Will return "white" if you run the script in one of these ways (quotes are optional but mandatory if you're going to use spaces): script.exe -color "white" script.exe --color white script.exe /color white Existence Example. The following code: #include "cmdline.au3" If _CmdLine_KeyExists('givemecoffee') Then ConsoleWrite('You want coffee.') Else ConsoleWrite('You do not want coffee.') EndIf Will return "You want coffee." if you run one of these: script.exe -givemecoffee script.exe --givemecoffee script.exe /givemecoffee And the following code: #include "cmdline.au3" If _CmdLine_ValueExists('givemecoffee') Then ConsoleWrite('You want coffee.') Else ConsoleWrite('You do not want coffee.') EndIf Will return "You want coffee." if you run one of these: script.exe givemecoffee script.exe "givemecoffee" Flags Example. This script: #include "cmdline.au3" ConsoleWrite("You want: ") If _CmdLine_FlagEnabled('C') Then ConsoleWrite("coffee ") EndIf If _CmdLine_FlagEnabled('B') Then ConsoleWrite("beer ") EndIf ConsoleWrite(" and you do not want: ") If _CmdLine_FlagDisabled('V') Then ConsoleWrite("vodka ") EndIf If _CmdLine_FlagDisabled('W') Then ConsoleWrite("wine ") EndIf ConsoleWrite(" but you did not tell me if you want: ") If Not _CmdLine_FlagExists('S') Then ConsoleWrite("soda ") EndIf If Not _CmdLine_FlagExists('J') Then ConsoleWrite("juice ") EndIf Will return "You want: coffee beer and you do not want: vodka wine but you did not tell me if you want: soda juice" if you run: script.exe +CB -VW Getting argument by its index You can also read the $CmdLine (1-based index) through this function. The advantage is that if the index does not exist (the user did not specify the argument), it won't break your script. It will just return the value you specify in the second function parameter. #include "cmdline.au3" $first_argument = _CmdLine_GetValByIndex(1, False) If Not $first_argument Then ConsoleWrite("You did not specify any argument.") Else ConsoleWrite("First argument is: " & $first_argument) EndIf Just a note: The second value of _CmdLine_GetValByIndex function can be an integer value, a string, a boolean value, an array or anything you want it to return if the index does not exist in $CmdLine array. This parameter is also available in _CmdLine_Get() function, also as a second function parameter. In this case, it will return this value if the key was not found. Example: #include "cmdline.au3" $user_wants = _CmdLine_Get("iwant", "nothing") ConsoleWrite("You want " & $user_wants) So, if you run: script.exe /iwant water It will return "You want water". But if you run just: script.exe It will return "You want nothing". Please note that, as these two are the only functions in this library meant to return strings, the second parameter is not available for the other functions. By default, if you do not specify any fallback value, it returns null if the wanted value could not be found. Also, please note that this UDF can NOT parse arguments in the format (key=value). Example: script.exe key=value IT WILL NOT WORK Here is the code: #include-once #comments-start CmdLine small UDF coder: Jefrey (jefrey[at]jefrey.ml) #comments-end Func _CmdLine_Get($sKey, $mDefault = Null) For $i = 1 To $CmdLine[0] If $CmdLine[$i] = "/" & $sKey OR $CmdLine[$i] = "-" & $sKey OR $CmdLine[$i] = "--" & $sKey Then If $CmdLine[0] >= $i+1 Then Return $CmdLine[$i+1] EndIf EndIf Next Return $mDefault EndFunc Func _CmdLine_KeyExists($sKey) For $i = 1 To $CmdLine[0] If $CmdLine[$i] = "/" & $sKey OR $CmdLine[$i] = "-" & $sKey OR $CmdLine[$i] = "--" & $sKey Then Return True EndIf Next Return False EndFunc Func _CmdLine_ValueExists($sValue) For $i = 1 To $CmdLine[0] If $CmdLine[$i] = $sValue Then Return True EndIf Next Return False EndFunc Func _CmdLine_FlagEnabled($sKey) For $i = 1 To $CmdLine[0] If StringRegExp($CmdLine[$i], "\+([a-zA-Z]*)" & $sKey & "([a-zA-Z]*)") Then Return True EndIf Next Return False EndFunc Func _CmdLine_FlagDisabled($sKey) For $i = 1 To $CmdLine[0] If StringRegExp($CmdLine[$i], "\-([a-zA-Z]*)" & $sKey & "([a-zA-Z]*)") Then Return True EndIf Next Return False EndFunc Func _CmdLine_FlagExists($sKey) For $i = 1 To $CmdLine[0] If StringRegExp($CmdLine[$i], "(\+|\-)([a-zA-Z]*)" & $sKey & "([a-zA-Z]*)") Then Return True EndIf Next Return False EndFunc Func _CmdLine_GetValByIndex($iIndex, $mDefault = Null) If $CmdLine[0] >= $iIndex Then Return $CmdLine[$iIndex] Else Return $mDefault EndIf EndFunc
    1 point
  3. even though a real great example @czardas also kudo's for you
    1 point
  4. dumous8343, I would do something like this: #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <GuiComboBox.au3> $sList = "8:00|8:30|9:00|9:30|10:00|10:30|11:00|11:30|12:00|12:30|13:00|13:30|14:00|14:30|15:00|15:30|16:00|16:30|17:00|17:30" $hGUI = GUICreate("Test", 500, 500) $CBDebut = GUICtrlCreateCombo("", 10, 10, 137, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL)) GUICtrlSetData(-1, $sList, "8:00") $CBFin = GUICtrlCreateCombo("", 10, 50, 137, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL)) GUICtrlSetData(-1, $sList, "12:00") $cRead = GUICtrlCreateButton("Read", 10, 100, 80, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cRead $iIndex_Debut = _GUICtrlComboBox_FindString($CBDebut, GUICtrlRead($CBDebut)) $iIndex_Fin = _GUICtrlComboBox_FindString($CBFin, GUICtrlRead($CBFin)) If $iIndex_Debut < $iIndex_Fin Then MsgBox($MB_SYSTEMMODAL, "Booking", "Accepted") Else MsgBox($MB_SYSTEMMODAL, "Error", "End must be after start") EndIf EndSwitch WEnd As long as the 2 combos have identical contents this will work. M23
    1 point
  5. Local $sProxyEnabled = RegRead ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyEnable") If $sProxyEnabled <> 0 Then Local $sProxyServer = RegRead ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyServer") If FileExist ( "C:\Temp\Output.txt" ) Then FileDelete ( "C:\Temp\Output.txt" ) FileWrite ("C:\Temp\Output.txt", $sProxyServer) Else Msgbox ( 0, "ProxyServer", "ProxyServer is not configured" ) EndIf Yup, FileWrite. Something like this.. See the help file for FileWrite / RegRead.
    1 point
  6. Surf243

    Set Acl permissions UDF

    Hey @AdamUL, I noticed an issue I had with FredAl's updated _MergeDaclToArray function as shown in post #50. I renamed the old function and added the new function to do a side-by-side comparison test. Here's my test: #RequireAdmin #include <Array.au3> #include 'Permissions.au3' #include <Security.au3> Global $aNewArray[1][4] Global $aOldArray[1][4] _InitiatePermissionResources() Global $sFile = "C:\log\folder1" $pDACL = _GetObjectDacl($sFile) _MergeDaclToArray_Old($pDacl, $aOldArray) _MergeDaclToArray_New($pDacl, $aNewArray) $iRows = UBound($aOldArray, $UBOUND_ROWS) - 1 For $i = 0 To $iRows $sUser = _Security__LookupAccountSid(_SidToStringSid(DllStructGetPtr($aOldArray[$i][0]))) $aOldArray[$i][0] = $sUser[1] & "\" & $sUser[0] ; Domain\Username $aNewArray[$i][0] = $sUser[1] & "\" & $sUser[0] ; Domain\Username Next _ArrayDisplay($aOldArray, "_MergeDaclToArray_Old") _ArrayDisplay($aNewArray, "_MergeDaclToArray_New") _ClosePermissionResources() I found 2 issues (see pics below): It changed the size of the array It left out the Inheritance flags This was an issue since we have permissions that use "List Folder Contents" which needs the flag to be 2 not 3 otherwise it looks like "Read-Only". So I compared the differences between both functions and modified it to get the results I needed. New Modified Function: (I commented on the changes I made) Func _MergeDaclToArray(ByRef $Dacl, ByRef $aPerm, $Filter = 1) If Not IsArray($aPerm) Or UBound($aPerm,2) < 3 Then Return SetError(1,0,0) Local $_EXPLICIT_ACCESS, $t_EXPLICIT_ACCESS = 'DWORD;DWORD;DWORD;ptr;DWORD;DWORD;DWORD;ptr' Local $aCall = DllCall($h__Advapi32Dll,'DWORD','GetExplicitEntriesFromAcl','ptr',$Dacl,'ulong*',0,'ptr*',0) If @error Or $aCall[0] Then Return SetError(2,0,0) Local $uB = UBound($aPerm), $l = 0, $TrusteeExists, $E = $aCall[2], $eaSID, $aPermSid, $pEa = $aCall[3] Local $aAce, $uB2 = UBound($aPerm,2) ; Add This Line For $i = 2 To $E $t_EXPLICIT_ACCESS &= ';DWORD;DWORD;DWORD;ptr;DWORD;DWORD;DWORD;ptr' Next $_EXPLICIT_ACCESS = DllStructCreate($t_EXPLICIT_ACCESS, $pEa) For $i = 0 To $uB -1 If Not IsDllStruct($aPerm[$i][0]) Then $aPerm[$i][0] = _GetSidStruct($aPerm[$i][0]) Next For $i = 0 To $E ; Changed from '1' to '0' $eaSID = DllStructGetData($_EXPLICIT_ACCESS, $l+8) $aAce = _GetAce($Dacl, $i) ; Added This Line If $eaSID = 0 Then ContinueLoop $TrusteeExists = 0 If $Filter Then For $c = 0 To $uB -1 $aCall = DllCall($h__Advapi32Dll,'BOOL','EqualSid','ptr',$eaSID,'ptr',DllStructGetPtr($aPerm[$c][0])) If Not @error Then $TrusteeExists = $aCall[0] If $TrusteeExists Then ExitLoop Next EndIf If Not $TrusteeExists And _IsValidSid($eaSID) Then ReDim $aPerm[$uB+1][$uB2] ; Changed from '3' to '$uB2' $aPerm[$uB][0] = DllStructCreate('byte SID['&_GetLengthSid($eaSID)&']',$eaSID) $aPerm[$uB][1] = Number(DllStructGetData($_EXPLICIT_ACCESS,$l+2) = 1) $aPerm[$uB][2] = DllStructGetData($_EXPLICIT_ACCESS,$l+1) If $uB2 > 3 Then $aPerm[$uB][3] = $aAce[3] ; Added This Line $uB += 1 EndIf $l += 8 Next Return $pEa EndFunc ;==> _MergeDaclToArray
    1 point
  7. funkey

    Binary Data for UDP

    You are right. It does not matter what structure points to the other one. DllStructCreate without pointer allocates the real memory. DllStructCreate with pointer points to the real memory location allocated first.
    1 point
  8. funkey

    Binary Data for UDP

    Looks good.
    1 point
  9. That is very useful. It is much better than what I had planned
    1 point
  10. There is a better way to approach this. Most weather services use airport codes or zip codes for locations. I don't have time at the moment but I remember seeing something like that in this forum somewhere when someone made a weather app. Use the search function and I bet you can find it. cheers! -Bert
    1 point
  11. But as a guess, try adding this to top of script, then you can look it up if you cannot deduce what it does. #AutoIt3Wrapper_UseX64=y
    1 point
  12. Sounds like a problem where supplying your OS (version, arch), IE version, AutoIt version, will help someone, who might be able to help you.
    1 point
  13. https://www.autoitscript.com/wiki/FAQ see faq 31 for some references As you build inhouse with visual studio its worth to look at the IUIAutomation stuff and check with SimpleSpy assuming developers are willing to use nice recognition id's. Other solution can be to use IUIAutomation from VBA / Excel 2010 or use the visual studio stuff that wraps UIAutomationCore.Dll
    1 point
  14. Hello. When I work with Net controls I usually do something like. #include <WinAPI.au3> Local $hWindow = WinGetHandle("Form1") Local $makeDirState = ControlCommand($hWindow, "", _MakeNetClassNN($hWindow, "BUTTON", "5"), "IsChecked", "") Func _MakeNetClassNN($hwnd, $sControlType, $sIndexNN) Local $sStringClass = _WinAPI_GetClassName($hwnd) Local $sStringWin = StringMid($sStringClass, 1, StringInStr($sStringClass, ".")) Return $sStringWin & $sControlType & StringMid($sStringClass, StringInStr($sStringClass, ".app")) & $sIndexNN EndFunc ;==>_MakeNetClassNN Saludos
    1 point
  15. @maniootek Sorry, I cannot show the code as its a project of one of my clients! Anyway, I have already found out the problem, the AV was blocking calls to the DLL!
    1 point
×
×
  • Create New...