Jump to content

amel27

Active Members
  • Posts

    34
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

amel27's Achievements

Seeker

Seeker (1/7)

1

Reputation

  1. Case $msg = $d And GUICtrlRead($a) = "C2641"
  2. $i = StringRegExp("AaAaAaA", "\u.") If @error Then MsgBox(16, "ERROR", "Code:"& @error &", Ext:"& @extended) Else MsgBox(0, "RESULT", $i) EndIf \L, \l brings into same result
  3. Are there any worked samples with this escape sequences from AutoIT HELP? Any attempts returns error in pattern.
  4. Mojo ERROR 5: "Access is denied", see System Error Codes dleigh This UDF use Microsoft DHCP API, therefore it work only with Windows DHCP servers, this API work via RPC and requires sufficient rights on DHCP server.
  5. This UDF write as probable solution of "Assigned Feature Request" (Ticket #588) RobSaunders, Valik and MsCreatoR Thanks for discussion $sString = "This is a Test, a _stringRegExpReplaceEx test" $sRetVar = _StringRegExpReplaceEx($sString, "\b(\w)(\w*)") $iRepCnt = @extended If @error Then MsgBox(16, "ERROR", "Err: "& @error &@CRLF& "Ext: "& @extended) Else MsgBox(64, "Results of ", StringFormat("Initial String:\n%s\n\nReturn String:\n%s\n\nSubstrings found: %s", $sString, $sRetVar, $iRepCnt)) EndIf ; ============================================================================= ; _StringRegExpReplaceEx($sString, $sPattern [,$sFunction]) ; ----------------------------------------------------------------------------- ; Replace text in a string based on regular expressions to text, ; returned by custom CallBack function ; ; $sString : The string to check ; $sPattern : The regular expression to compare. ; $sFunction : Callback Function Name ; ; Return Value : Final String ; ; @Error Meaning ; 0 Check @Extended for the number of replacements performed. ; 2 Pattern invalid. @Extended = offset of error in pattern. ; ============================================================================= Func _StringRegExpReplaceEx($sString, $sPattern, $sFunction = "_StringRegExpReplaceCallBack") Local Const $aBlank[10] = ['','','','','','','','','',''] Local $aM1, $aM2, $sStrip, $aStrip, $aGroups, $sResult = "" $sStrip = StringRegExpReplace($sString, $sPattern, Chr(0)) If @error Then Return SetError(@error, @extended, $sString) $aStrip = StringSplit($sStrip, Chr(0)) $aM1 = StringRegExp($sString, $sPattern, 4) If IsArray($aM1) Then For $i=0 To UBound($aM1)-1 $aGroups = $aBlank $aM2=$aM1[$i] For $j=0 To UBound($aM2)-1 $aGroups[$j]=$aM2[$j] Next $sResult &= $aStrip[$i+1] $sResult &= Call($sFunction, $aGroups) Next EndIf $sResult &= $aStrip[$aStrip[0]] Return SetError(0, UBound($aM1), $sResult) EndFunc ;==> _StringRegExpReplaceEx ; ============================================================================= ; _StringRegExpReplaceCallBack ($aGroups) ; ----------------------------------------------------------------------------- ; Custom user function for building replacement string ; base on found string and substrings (capture groups) ; ; $aGroups : Array of searched substrings ; ; : $aGroups[0] equal to "\0" ; : $aGroups[1] equal to "\1" ; : ... ; ; Return Value : Replacement string ; ============================================================================= Func _StringRegExpReplaceCallBack($aGroups) Switch $aGroups[1] Case "_" Return "_" & StringUpper(StringLeft($aGroups[2], 1)) & StringTrimLeft($aGroups[2], 1) Case "t", "T" Return StringUpper($aGroups[0]) Case Else Return $aGroups[0] EndSwitch EndFunc ;==> _StringRegExpReplaceCallBack
  6. Thanks for answer! Yes, I see that structures works by pointers - direct passing have increment internal AutoIT counter of pointers, passing ByRef use original pointer. But it is not obvious that structures must work as Objects (via pointers) rather than as Arrays (via data).
  7. $t = DllStructCreate("int") DllStructSetData($t, 1, 111) ; Question 1: Is Structures passed ALWAYS "ByRef"? ConsoleWrite(DllStructGetData($t,1)&@CRLF) _Test1($t) ConsoleWrite(DllStructGetData($t,1)&@CRLF&@CRLF) ; Question 2: Is Structures returned ALWAYS By Reference too? ConsoleWrite(DllStructGetPtr($t)&@CRLF) $u=_Test1($t) ConsoleWrite(DllStructGetPtr($u)&@CRLF&@CRLF) Func _Test1($x) DllStructSetData($x, 1, 888) ; ReSet Structure Return $x EndFunc
  8. - add returning of client Lease Expires Time Attribute; - _DHCP_EnumSubnets() support unlimited scopes
  9. thx devide one huge UDF into two more readable
  10. - add new optional parameter "Type of Search Info" for strong typing - add supported of Native data format for quick exchange with others API functions: "Int" (aka "dword") for IP Address/Mask "Binary" for Hardware (MAC) address
  11. #include <Date.au3> ;=============================================================================== ; ; Description: Get DHCP Client Attributes by IP Address, MAC or Name ; Parameter(s): $sDHCP - IP Address of DHCP Server ; $ClientID - Client IP, MAC or Name (String or Native Format) ; Integer - native format for IP Address/Mask ; Binary - native format for MAC Address (6 bytes) ; $iIDType - type of ClientID information: ; 0 - Auto-define by value ; 1 - Client IP address ; 2 - Client Hardware (MAC) address ; 3 - Client Name ; $iFlags - Config Flags: ; 0x1- Output Format (0-Text, 1-Native) ; Requirement(s): Testing ; Return Value(s): On Success - The array of parameters with indexes ; 0 - Client IP address ; 1 - Client IP subnet mask ; 2 - Client MAC address ; 3 - Client Name ; 4 - Client Comment ; 5 - Client Lease Expires Time ; On Failure - Null, @error set to ; 1 - Client not found on DHCP server ; 2 - Invalid ClientID parameter ; 3 - Operating System not supported ; 4 - Any Runtime Error, API Error Code set to @extended ; Author(s): amel27 (Alexander Melnichuk) ; Note(s): Client Name is case sensitive ; ;=============================================================================== Func _DHCP_GetClientInfo($sDHCP, $ClientID, $iIDType=0, $iFlags=0) ; Create DHCP_SEARCH_INFO Structure Local $tSearchInfo= DllStructCreate("int SearchType;int DataLength;ptr DataPtr") Local $iSearchInfoPtr = DllStructGetPtr($tSearchInfo), $aSubnets[2]=[1,0], $iType=0 Local $tBinaryData = DllStructCreate("dword SubnetIPAddress;ubyte HardwareID;ubyte MACAddress[6]") ; Check Client ID Parameter and Define SearchInfo Type If IsInt($ClientID) Then If $iIDType=0 Or $iIDType=1 Then $iType = 1 ElseIf IsBinary($ClientID) Then If BinaryLen($ClientID)=6 And ($iIDType=0 Or $iIDType=2) Then $iType = 2 ElseIf IsString($ClientID) Then If StringRegExp($ClientID, "^(\d+\.){3}\d+$") Then ; Get IP DWord type from String Local $aOctets = StringSplit($ClientID, "."), $iClientIP = 0 For $i=1 To 4 If BitAND($aOctets[$i], 0xFFFFFF00) Then Return SetError(2) ; ERR: Invalid Client IP Address $iClientIP = BitOR(BitRotate($iClientIP, 8, "D"), $aOctets[$i]) Next $ClientID = $iClientIP If $iIDType=0 Or $iIDType=1 Then $iType = 1 ElseIf StringRegExp($ClientID,"^(0[xX])?[[:xdigit:]]{2}((:|-)?[[:xdigit:]]{2}){5}$") Then $ClientID = Binary("0x"& StringRegExpReplace($ClientID,"(0[xX]|:|-)","")) If $iIDType=0 Or $iIDType=2 Then $iType = 2 Else If $iIDType=0 Or $iIDType=3 Then $iType = 3 EndIf EndIf If $iType =0 Then Return SetError(2) ; Route the filling of DHCP_SEARCH_INFO structure Switch $iType Case 1 ; Filling DHCP_SEARCH_INFO for search by client IP address Local $tSearchInfo_IP = DllStructCreate("int SearchType;dword ClientIPAddress", $iSearchInfoPtr) DllStructSetData($tSearchInfo_IP, "SearchType", 0) DllStructSetData($tSearchInfo_IP, "ClientIPAddress", $ClientID) Case 2 ; Filling DHCP_SEARCH_INFO for search by client MAC address DllStructSetData($tSearchInfo, "SearchType", 1) DllStructSetData($tSearchInfo, "DataLength", 11) DllStructSetData($tSearchInfo, "DataPtr", DllStructGetPtr($tBinaryData)) ; Filling DHCP_BINARY_DATA DllStructSetData($tBinaryData, "HardwareID", 0x01) DllStructSetData($tBinaryData, "MACAddress", $ClientID) ; Get Array of DHCP Subnets $aSubnets = _DHCP_EnumSubnets($sDHCP, 1) If @error=1 Then Return SetError(1) If @error=2 Then Return SetError(4, @extended) Case 3 ; Filling DHCP_SEARCH_INFO for search by client Name Local $tSearchInfo_Name = DllStructCreate("int SearchType;ptr ClientNamePtr", $iSearchInfoPtr) Local $tClientNameString= DllStructCreate("wchar ClientName["& StringLen($ClientID)+1 &"]") DllStructSetData($tSearchInfo_Name, "SearchType", 2) DllStructSetData($tSearchInfo_Name, "ClientNamePtr", DllStructGetPtr($tClientNameString)) DllStructSetData($tClientNameString, "ClientName", $ClientID) EndSwitch ; Call DhcpGetClientInfo API function Local $tClientInfo_Ptr = DllStructCreate("ptr"), $aRet, $aRes[6] For $i=1 To $aSubnets[0] DllStructSetData($tBinaryData, "SubnetIPAddress", $aSubnets[$i]) $aRet = DllCall("Dhcpsapi.dll", "int", "DhcpGetClientInfo", _ "wstr", $sDHCP, _ "ptr", $iSearchInfoPtr, _ "ptr", DllStructGetPtr($tClientInfo_Ptr) ) If @error Then Return SetError(3, @error) ; ERR: Invalid DLL or Function Name If $aRet[0]<>20013 Then ExitLoop Next If $aRet[0]=20013 Then Return SetError(1, $aRet[0]) ; ERR: Client not found If $aRet[0] Then Return SetError(4, $aRet[0]) ; ERR: Any runtime errors ; DHCP_CLIENT_INFO structure Local $tClientInfo = DllStructCreate("dword ClientIpAddress;dword SubnetMask;int BinaryLen;ptr BinaryPtr;" & _ "ptr ClientNamePtr;ptr ClientCommentPtr;ubyte ClientLeaseExpires[8];dword OwnerHostIPAddress;" & _ "ptr OwnerHostNetBiosNamePtr;ptr OwnerHostNamePtr", DllStructGetData($tClientInfo_Ptr,1)) Local $tClientBinary = DllStructCreate("ubyte BinaryData[6]", DllStructGetData($tClientInfo, "BinaryPtr")) ; Get IP Address $aRes[0] = DllStructGetData($tClientInfo, "ClientIpAddress") If BitAND($iFlags,1)=0 Then $aRes[0] = BitRotate(BitAND($aRes[0],0xFF000000), 8,"D") &"."& _ BitRotate(BitAND($aRes[0],0x00FF0000),16,"D") &"."& _ BitRotate(BitAND($aRes[0],0x0000FF00),-8,"W") &"."& BitAND($aRes[0],0x000000FF) ; Get IP Mask $aRes[1] = DllStructGetData($tClientInfo, "SubnetMask") If BitAND($iFlags,1)=0 Then $aRes[1]=BitRotate(BitAND($aRes[1],0xFF000000), 8,"D") &"."& _ BitRotate(BitAND($aRes[1],0x00FF0000),16,"D") &"."& _ BitRotate(BitAND($aRes[1],0x0000FF00),-8,"W") &"."& BitAND($aRes[1],0x000000FF) ; Get MAC Address $aRes[2] = DllStructGetData($tClientBinary, "BinaryData") If BitAND($iFlags,1)=0 Then $aRes[2] = String($aRes[2]) ; Get Client Name Local $tClientNameString = DllStructCreate("wchar ClientName[255]", DllStructGetData($tClientInfo, "ClientNamePtr")) $aRes[3] = DllStructGetData($tClientNameString, "ClientName") ; Get Client Comment Local $tClientNameString = DllStructCreate("wchar ClientComment[255]", DllStructGetData($tClientInfo, "ClientCommentPtr")) $aRes[4] = DllStructGetData($tClientNameString, "ClientComment") ; Get Client Lease Expire Time $aRes[5] = DllStructGetData($tClientInfo, "ClientLeaseExpires") If BitAND($iFlags,1)=0 Then $aRes[5] = _Date_Time_FileTimeToLocalFileTime(DllStructGetPtr($tClientInfo, "ClientLeaseExpires")) $aRes[5] = _Date_Time_FileTimeToStr($aRes[5]) EndIf ; Freeing a memory DllCall("Dhcpsapi.dll", "none", "DhcpRpcFreeMemory", "ptr", DllStructGetData($tClientInfo_Ptr,1)) Return $aRes EndFunc ;==> _DHCP_GetClientInfo ;=============================================================================== ; ; Description: Get List of DHCP Scopes ; Parameter(s): $sDHCP - IP Address of DHCP Server ; $iFlags - Config Flags: ; 0x1- Output Format (0-Text, 1-Native) ; Requirement(s): Testing ; Return Value(s): On Success - The array subnet of IP Addresses ; element with index 0 is count of scopes ; On Failure - @error set to ; 1 - Scopes not defined, returned empty array ; 2 - Any Runtime Error, invalid array, ; API Error Code set to @extended ; Author(s): amel27 (Alexander Melnichuk) ; Note(s): ; ;=============================================================================== Func _DHCP_EnumSubnets($sDHCP, $iFlags=0) Local $tEnumSubnetsParms = DllStructCreate("hwnd ResumeHandle;ptr EnumInfoPtr;int ElementsRead;int ElementsTotal") Local $aSubnets[1]=[0], $tIPArray, $tAddress, $aRet Do $aRet = DllCall("Dhcpsapi.dll", "int", "DhcpEnumSubnets", _ "wstr", $sDHCP, _ "ptr" , DllStructGetPtr($tEnumSubnetsParms, "ResumeHandle"), _ "int", 100, _ "ptr" , DllStructGetPtr($tEnumSubnetsParms, "EnumInfoPtr") , _ "ptr" , DllStructGetPtr($tEnumSubnetsParms, "ElementsRead"), _ "ptr" , DllStructGetPtr($tEnumSubnetsParms, "ElementsTotal") ) If $aRet[0] Then Return SetError(2, $aRet[0]) ; ERR: Any runtime errors If DllStructGetData($tEnumSubnetsParms,"EnumInfoPtr")=0 Then Return SetError(1, 0, $aSubnets) ; ERR: Not Found $tIPArray = DllStructCreate("int NumElements;ptr Elements", DllStructGetData($tEnumSubnetsParms,"EnumInfoPtr")) ReDim $aSubnets[$aSubnets[0] + DllStructGetData($tIPArray,"NumElements") +1] For $i=$aSubnets[0]+1 To UBound($aSubnets)-1 $tAddress = DllStructCreate("dword SubNetAddess", DllStructGetData($tIPArray,2) + ($i-$aSubnets[0]-1)*4) $aSubnets[$i]=DllStructGetData($tAddress, "SubNetAddess") If BitAND($iFlags,1)=0 Then $aSubnets[$i] = BitRotate(BitAND($aSubnets[$i],0xFF000000), 8,"D") _ &"."& BitRotate(BitAND($aSubnets[$i],0x00FF0000),16,"D") _ &"."& BitRotate(BitAND($aSubnets[$i],0x0000FF00),-8,"W") _ &"."& BitAND($aSubnets[$i],0x000000FF) Next $aSubnets[0] += DllStructGetData($tIPArray,"NumElements") Until DllStructGetData($tEnumSubnetsParms,"ElementsRead") = DllStructGetData($tEnumSubnetsParms,"ElementsTotal") ; Freeing a memory DllCall("Dhcpsapi.dll", "none", "DhcpRpcFreeMemory", "ptr", DllStructGetData($tEnumSubnetsParms,"EnumInfoPtr")) Return $aSubnets EndFunc ; => _DHCP_EnumSubnets
  12. AFAIK DHCP Scopes may be returned only via DHCP API, included in Widows Server 2000/2003 operating systems
  13. nitron, try this WinAPI UDFs ; ================================================================================================== ; Name...........: _NetAPI_GroupAddUser ; Description ...: Gives an existing user account membership in an existing global group ; Syntax.........: _NetAPI_GroupAddUser($sUser, $sGroup, $sServer) ; Parameters ....: $sUser - User to be given membership in the Global Group ; : $sGroup - Name of the Global Group in which the User is to be given membership ; : $sServer - DNS or NetBIOS name of the remote Server or Null for Local use ; Return values .: Success - True ; Failure - False and @Extended set error NERR code ; Author ........: amel27 ; Example .......: _NetAPI_GroupAddUser ("User", "Domain Admins", "DC1") ; =================================================================================================== Func _NetAPI_GroupAddUser($sUser, $sGroup, $sServer = '') Local $aRet = DllCall("netapi32.dll", "int", "NetGroupAddUser", "wstr", $sServer, "wstr", $sGroup, "wstr", $sUser) If $aRet[0] Then Return SetError(1, $aRet[0], False) Return True EndFunc ; ==> _NetAPI_GroupAddUser ; =================================================================================================== ; Name...........: _NetAPI_LocalGroupAddMember ; Description ...: Adds membership of one existing user or global group account to an existing local group ; Syntax.........: _NetAPI_LocalGroupAddMember($sAccount, $sGroup, $sServer) ; Parameters ....: $sAccount - Account name of the Local Group member prefixed by the domain name and the "\" separator ; : $sGroup - Name of the Local Group to which the specified users or global groups will be added ; : $sServer - DNS or NetBIOS name of the remote Server or Null for Local use ; Return values .: Success - True ; Failure - False and @Extended set error code ; Author ........: amel27 ; Example .......: _NetAPI_LocalGroupAddMember ("Domain\User", "Administrators") ; =================================================================================================== Func _NetAPI_LocalGroupAddMember($sAccount, $sGroup, $sServer = '') Local $twUser = DllStructCreate("wchar["& StringLen($sAccount)+1 &"]") Local $tpUser = DllStructCreate("ptr") DllStructSetData($twUser, 1, $sAccount) DllStructSetData($tpUser, 1, DllStructGetPtr($twUser)) Local $aRet = DllCall("netapi32.dll", "int", "NetLocalGroupAddMembers", _ "wstr", $sServer, "wstr", $sGroup, "int", 3, "ptr", DllStructGetPtr($tpUser), "int", 1 ) If $aRet[0] Then Return SetError(1, $aRet[0], False) Return True EndFunc ; ==> _NetAPI_LocalGroupAddMember
  14. Thanks rover! I see that now Binary data type are closed... But how direct editing binary data without converting it to string?
  15. since new Unicode AutoIT versions this lengths not equal: $u = DllStructCreate ('byte[10]') ConsoleWrite ("Size of structure: "& DllStructGetSize ($u) &@CRLF) ConsoleWrite ("Size of data in structure: "& StringLen (DllStructGetData ($u,1)) &@CRLF)oÝ÷ Ù«­¢+ØÀÌØíÍ¥±ô]¥¹½ÝͥȵÀìÌäìÀäÈíÍÑÕÁй±½Ìäì(ÀÌØí¡¥±ô¥±=Á¸ ÀÌØíÍ¥±°Ð¤() ½¹Í½±]É¥Ñ ÅÕ½ÐíM¥é½¥±èÅÕ½ÐìµÀ쥱ÑM¥é ÀÌØíÍ¥±¤µÀí I1¤) ½¹Í½±]É¥Ñ ÅÕ½ÐíM¥é½Ñ¥¸¥±èÅÕ½ÐìµÀìMÑÉ¥¹1¸¡¥±I ÀÌØí¡¥±±¥±ÑM¥é ÀÌØíÍ¥±¤¤¤µÀí I1¤)¥± ±½Í ÀÌØí¡¥±¤
×
×
  • Create New...