Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 08/23/2014 in all areas

  1. Automate all windows and browser applications with one UDF function library. Based on the microsoft automation API this library high level supports Recognition of conttrols from EDGE, Chrome, FF, Opera, Safari and Windows native apps Small testing framework to split object repository from coding away Introduction Quickstart - Getting started quickly Simple scripts With this module you can automate all applications/programs that support ui automation and/or accesibility api from microsoft you can recognize more controls than AutoIT can recognize "out of the box" you can use concepts from other testing frameworks like http://download.freedesktop.org/ldtp/doc/ldtp-tutorial.pdf http://safsdev.sourceforge.net/Default.htm coded ui testing from microsoft Some of those controls / applications are chrome browser (partly mainwindow has to be done with MSAA for navigating) chrome://accessibility in the adress bar of chrome or start with "--force-renderer-accessibility" silverlight controls Ribbon control controlbars of Excel/Word IE and FF browsers Windows Media Player Windows clock AFX .. controls (partly) .... Based on the initial AIO Object I now have made the interface file to work with objCreateInterface function which is in the latest beta's automate clicking and querying basic information It gives you a lot of basic information to be able to automate clicking, querying basic information where it goes further in certain situations than AutoIt is identifying Starting threads for background on the ui automation api of microsoft (not for starters) http://en.wikipedia.org/wiki/Microsoft_UI_Automation http://msdn.microsoft.com/en-us/library/ms747327.aspx Previous threads in general help/support Interface AutoItObject IUIAutomation ObjCreateInterface and struct tagPoint in method ElementFromPoint Be aware that API is not allways installed under XP/Vista see http://support.microsoft.com/kb/971513 Within Windows 7 and Windows 8 it should be preinstalled by default. Be aware on 32 and 64 bits way of running your script #AutoIt3Wrapper_UseX64=Y or N Basic example of usage / showing and retrieving the default information, will post multiple examples later Hover your mouse to an area of interest and press ctrl+w and information will be shown in the edit box of the form Simple spy demo (see simplespy.au3 or use latest ZIP attachment for latest version) Main features Recognize windows and html controls for the major browsers Logical and physical description for controls (UI mapping, Application map) Simple repository logic to abstract logical and physical descriptions Store Runtime Type Information in RTI. variables Rubberbanding/highlighting of objects Simple spy to help in making / identifying the physical description Support of regular expression(s) in identifying objects recognize objects on multiple properties supported properties: name ,title, automationid, classname, class, iaccessiblevalue, iaccessiblechildId, controltype, processid, acceleratorkey The actions provided so far "leftclick", "left", "click", "leftdoubleclick", "leftdouble", "doubleclick", _ "rightclick", "right", "rightdoubleclick", "rightdouble", _ "middleclick", "middle", "middledoubleclick", "middledouble", "mousemove", "movemouse" "setvalue","settextvalue" "setvalue using keys" "setValue using clipboard" "getvalue" "sendkeys", "enterstring", "type", "typetext" "invoke" "focus", "setfocus", "activate" "close" "move","setposition" "resize" "minimize", "maximize", "normal", "close", "exist", "exists" "searchcontext", "context" "highlight" "getobject","object" "attach" "capture","screenshot", "takescreenshot" "dump", "dumpthemall" "propertyvalue", "property" match on multiple properties like: name:=((Zoeken.*)|(Find.*)); ControlType:=Button; acceleratorkey:=Ctrl+F Support for 117 different properties see $UIA_propertiesSupportedArray in uiawrappers like for example title, regexptitle, class, regexpclass, iaccessiblevalue, iaccessiblechildid, name, accesskey, automationid, classname IAccessible, IAccessible2, ISimpleDom interfaces debuglogging to a file log.txt (no output in scitewindow) Examples Example 1 Iterating thru the different ways of representing the objects in the tree (#comment-1105548) Example 2 Finding the taskbar and clicking on the start menu button (#comment-1105680) Example 3 Clicking a litlle more and in the end displaying all items from the clock (thats not directly possible with AU3Info) (#comment-1108849) Example 4 that demonstrates the calculator Example 5 Automating chrome Example 6 Demonstrates all stuff within chrome to navigate html pages, find hyperlink, click hyperlink, find picture, click picture, enter data in inputbox Example 7 The chrome example modified to a firefox example Example 8 The other major browser Internet Explorer automated (made on Example 6 and 7) Example 9 Windows media player Example 10 Automating mach 3 (AFX windows and other hard to get recognized by AutoIT) Lot of links are broken due to forum upgrade just search for the text like "Example 11 Demonstrate Word, Notepad and Calculator actions" Example 11 Demonstrate Word, Notepad and Calculator actions ... Example 13 Details 1 about the right pane of the windows explorer Example 14 Details 2 about the right pane of the windows explorer Example 15 Details 3 about the right pane of the windows explorer Example 16 Details 4 about the right pane of the windows explorer Example 17 Details 5 about the right pane of the windows explorer WITH CACHING Example 18 Details 6 about the right pane of the windows explorer WITH VIRTUAL ITEMS Example 19 Eventhandling examples Example 20 Eventhandling examples Example 21a Eventhandling examples Internet Explorer Example 21b Eventhandling examples Internet Explorer Example 22 Eventhandling examples Follow focus Example 23 Eventhandling examples structure changed Example 24 Eventhandling examples IUIAutomationEventHandler Example 25 SAFEARRAYS Example 26 IACCESSIBLE / MSAA Example 27 IACCESSIBLE2 / MSAA Example 28 IACCESSIBLE / MSAA events Example 29 IACCESSIBLE2 events Example 30 ISimpleDOM Example 31 Notepad window move, maximize, minimize Example 32 Three browsers doing the same stuff with small differences in scripting only .. TODO Build recorder Enhance the spy with a nicer UI UI for the repository (now in the script with dot notation) Enhance mapping / identifying on multiple properties instead of 1 combined with index If speed becomes an issue use the caching logic of the MS UIA framework Add the other patterns later Generalize the concept of System Under Test of starting the SUT (for testing framework purposes) Remote running of scripts Fix issue on finding within dynamic context ... edit august 18th 2013 initial post Only zip files are needed to download , just unzip in 1 directory edit july 2016 Made V0_63 and examples works with AutoIt v3.3.14 Windows 10 tested Simple spy gives some basic code as a present Chrome latest versions seems to be having issues with IUIAutomation on tabs/buttons of mainwindow use MSAA for accessing tabsheets / buttons more cleanup to be in UDF style More comments in the source see changelog.txt for previous changes edit september 2017 All examples fixed for the IE, Firefox and Chrome browser Some small but essential fixes in UIAWrappers edit april 2018 Enhanced logic on fallback / dynamic search, still not perfect, to slow Retested with latest Chrome, FF, Edge and IE11 and some extensions to show how to get text from the webpage (examples 5,6,7) Some small bugfixes Some comments as given in forum incorporated edit may 2019 Speed enhancements on especially fallback searching UIA.CFG works now in a better way to turn on/off debug, highlighting, debug2file More stable and consistent behavior Internal cleanup and refactoring of bigger functions Checked with W10 (not tested on W7) Added some W10 properties Run with 3.3.14.5 on W10 UIA_V0_51.zip EXAMPLES_V0_5.zip UIA_V0_63.zip EXAMPLES_V0_63.zip UIA_V0_64.zip EXAMPLES_V0_64.zip EXAMPLES_V0_66.zip UIA_V0_66.zip EXAMPLES_V0_70.zip UIA_V0_70.zip
    1 point
  2. IE Embedded Control Versioning Use IE 9+ and HTML5 features inside a GUI This UDF allows the use of embedded IE controls which support IE versions greater than IE 7. By default, all embedded IE controls default to IE 7 compatibility mode (unless for some reason somebody has IE 6 installed!), so its not possible to use most of the HTML5 features available today. Fortunately, IE 9 and greater allow the use of HTML5, and the embedded IE control actually supports it. The problem is convincing Windows to let your program actually use those features! There are Registry branches that modify how an IE control works in specific programs. Those branches are: HKCU\Software\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION HKLM\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION In at least one of these branches, the executable name needs to appear as a value name ("autoit.exe" for example), and the value data needs to indicate what IE version to 'emulate'. The value data is actually dependent on the version and whether quirks-mode is enabled. See Web Browser Control - Specifying the IE Version for more information. Note that a 64-bit O/S needs adjustments to the HKLM paths. Also, prefer the HKCU branch unless the program needs to enable access across all user accounts. HTML5 Canvas Element Example Anyway, all the complexity of setting the right value with the right name with the right 32/64-bit branch is handled for you in this UDF. Enabling support for IE9+, and new HTML5 features, is as simple as making one call to _IE_EmbeddedSetBrowserEmulation(). _IE_EmbeddedSetBrowserEmulation() takes an executable name (@AutoItExe if none is provided), and checks the Registry for an entry for it. If it doesn't find one, it will create one and enable support for later versions of IE. The full parameters to the function are as follows: _IE_EmbeddedSetBrowserEmulation($nIEVersion, $bIgnoreDOCTYPE = True, $bHKLMBranch = False, $sExeName = @AutoItExe) The parameter passed in $nIEVersion can be anything from 8 to 11 [or 12+ in the future], or just the current version of IE, which is available also through a call to _IE_EmbeddedGetVersion(). $bIgnoreDOCTYPE controls when IE will go into quirks mode based on any "<!DOCTYPE>" declarations on webpages. This mode can cause major problems, so by default it is set to ignore it (set this to False to enable it). $bHKLMBranch controls where in the registry the Browser Emulation Mode setting will be stored. If you wish to store the mode for ALL users, set this parameter to True. Note, however, that elevated privileges are required for modifying the HKLM branch! If the call to _IE_EmbeddedSetBrowserEmulation() is successful, then you can enable a (more) HTML5 compliant IE browser control in a GUI. The complete set of functions in the UDF: _IE_EmbeddedGetVersion() ; Gets version of IE Embeddable Control (from ieframe.dll or Registry) _IE_EmbeddedGetBrowserEmulation() ; Gets Browser Emulation Version for given Executable (or 0 if not found) _IE_EmbeddedSetBrowserEmulation() ; Sets Browser Emulation Version. NOTE: HKLM branch REQUIRES ELEVATED PRIVILEGES! _ IMPORTANT: Setting the embedded browser object to a newer version of IE may alter the behavior of some things. See documenation for the HTMLDocumentEvents2 interface and HTMLAnchorEvents2 interface for example. Also, there is at least one difference in behavior noted by mesale0077 in working with IE10 (and possibly other versions of IE) - clicks for elements inside an <a> anchor tag will register as the actual internal element rather than the surrounding anchor. For example, an <img> element wrapped by an <a> anchor will only send the click to the <img> element and not propagate it any further. A workaround for this is to check the parentNode to see if it is an <a> element. See the discussion in the >ObjEvent dont work thread. It could be that there's some other reason for this behavior, but nothing has come to light yet. As an aside, also see trancexx's response in >ObjEvent usage for more techniques for capturing IE events. History: An example of HTML5 use, which has a little interactive Canvas, follows (requires IE9 or higher!): #include "IE_EmbeddedVersioning.au3" ; =============================================================================================================================== ; <IE_EmbeddedHTML5Example.au3> ; ; Example of using 'IE_EmbeddedVersioning' UDF ; ; This example 1st attempts to set the Browser Emulation information in the registry, then ; creates an embedded IE control with an interactive HTML5 Canvas element. ; ; Author: Ascend4nt ; =============================================================================================================================== #Region IE_CANVAS_EXAMPLE #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <IE.au3> ; ----------- ; GLOBALS ; ----------- Global $bMouseDown = False, $iLastX1 = 0, $iLastY1 = 0 Global $g_oCanvas, $g_oCtx Global $hGUI, $ctGUI_ErrMessageLabel Global $GUI_IE_Obj Global $nRet = _WinMain() ; Optionally remove valuename at Exit (not recommended if compiled to executable) ;~ _IE_EmbeddedRemoveBrowserEmulation() Exit $nRet ; ====================================================================================================== ; Embedded IE Browser-Emulation Fix + HTML5 Example ; ====================================================================================================== Func _WinMain() ConsoleWrite("@AutoItX64 = " & @AutoItX64 & ", IsAdmin() = " & IsAdmin() & @CRLF) ;; Get Current IE Embeddable Control Version (from ieframe.dll) Local $sIEVer = _IE_EmbeddedGetVersion(), $nIEVer = @extended ConsoleWrite("Embedded Version = " & $sIEVer & ", as Int: " & $nIEVer & ", @error = " & @error & @CRLF) ; Old IE version w/o HTML5 support? Exit If $nIEVer < 9 Then Return MsgBox(0, "Old IE Version", "IE version is less than 9, HTML5 example will not work") ;; Current Browser Emulation Mode for this executable (if exists) Local $nIEBEVer = _IE_EmbeddedGetBrowserEmulation() ConsoleWrite("GetEmbeddedVersion: " & $nIEBEVer & ", @error = " & @error & ", @extended = " & @extended & @CRLF) ;; Set Browser Emulation Mode for this executable (if not already set or set to a different version) ; HKCU Branch: _IE_EmbeddedSetBrowserEmulation() ; HKLM Branch: ;_IE_EmbeddedSetBrowserEmulation(-1, True, True) If @error Then ; -1 error means trying to access HKLM, so script needs elevation to access the Registry If @error = -1 Then If MsgBox(32 + 3, "Elevation Required", "Elevate script to enable setting Browser Emulation Mode?") = 6 Then Return _ReRunIfNotElevated() Return 1 EndIf Return MsgBox(0, "Error", "Couldn't set Browser Emulation mode") EndIf ;Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc") ;; Create Embedded Browser Control and GUI Local $oIE = _IECreateEmbedded() ; GUI (vars are Global) $hGUI = GUICreate("Embedded Web control Test", 460, 360, -1, -1, $WS_OVERLAPPEDWINDOW + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN) $GUI_IE_Obj = GUICtrlCreateObj($oIE, 10, 10, 440, 340) $ctGUI_ErrMessageLabel = GUICtrlCreateLabel("", 100, 500, 500, 30) GUICtrlSetColor(-1, 0xff0000) GUISetState(@SW_SHOW) ;Show GUI ; Doesn't work (at least for keyboard focus): ;~ ControlFocus($hGUI, '', $GUI_IE_Obj) ;; Initialize Embedded Control and write some HTML5 data to it _IENavigate($oIE, 'about:blank' ) ; Basic Near-Empty HTML (with minimal CSS styling for Canvas element) Local $sHTML = '<!DOCTYPE html>' & @CR & '<html>' & @CR & '<head>' & @CR & _ '<meta content="text/html; charset=UTF-8" http-equiv="content-type">' & @CR & _ '<title>Experiments</title>' & @CR & _ '<style>canvas { display:block; background-color:white; outline:#00FF00 dotted thin;}</style>' & @CR & _ '</head>' & @CR & '<body>' & @CR & '</body>' & @CR & '</html>' _IEDocWriteHTML($oIE, $sHTML) _IEAction($oIE, "refresh") ;; Setup Event Object Functions Local $oEventsDoc = ObjEvent($oIE.document, "Event_", "HTMLDocumentEvents2") #forceref $oEventsDoc ;~ ConsoleWrite("Obj Name = " & ObjName($oIE) & @CRLF) ;~ ConsoleWrite("Location = " & $oIE.document.location.pathname & @CRLF) ; -------------------------------------------------------------------------------------- ; Create Canvas Element through the DOM (optionally just add it in the HTML5 above) ; ------------------------------------------------- ; Note: Support in browsers, see "Can I use..." ; @ http://caniuse.com/#feat=canvas ; and @ http://caniuse.com/#search=canvas ; ------------------------------------------------- ; IE minimum is version 9+, 10+ has more features, but WebGL support requires version 11+ ; -------------------------------------------------------------------------------------- $g_oCanvas = $oIE.document.createElement("canvas") $g_oCanvas.id = "myCanvas" ;~ ConsoleWrite("Canvas ID = " & $g_oCanvas.id & @CRLF) $oIE.document.body.appendChild($g_oCanvas) ; Optionally, if added already through the HTML5 text: ;Local $g_oCanvas = _IEGetObjById($oIE, "myCanvas") If @error Then Return MsgBox(0, "Error", "Error creating/accessing Canvas") ;; Tweak Canvas Size, Move into View ;~ ConsoleWrite("window innerwidth = " & $oIE.document.parentWindow.innerWidth & @CRLF) ;$oIE.document.parentWindow.scrollTo(0, 10) $g_oCanvas.width = 420 $g_oCanvas.height = 320 ;ConsoleWrite("Canvas item offsetTop = " & $g_oCanvas.offsetTop & @CRLF) $g_oCanvas.scrollIntoView() ;; Grab the Canvas 2D Context $g_oCtx = $g_oCanvas.getContext("2d") ;; Example Drawing: Gradiant Local $oGrad = $g_oCtx.createLinearGradient(0,0,0,60) If IsObj($oGrad) Then $oGrad.addColorStop(0, "red") $oGrad.addColorStop(1, "blue") $g_oCtx.fillStyle = $oGrad EndIf $g_oCtx.fillRect(0,0,419,60) ;; Example Drawing: Text $g_oCtx.font = "30px serif" $g_oCtx.fillStyle = "white" $g_oCtx.textBaseline = "top" $g_oCtx.fillText("HTML5 Canvas Drawing!", 50, 10) ;; Example Drawing: Circle, Line $g_oCtx.beginPath() $g_oCtx.arc(200, 100, 20, 0, ACos(-1) * 2) $g_oCtx.fillStyle = "red" $g_oCtx.fill() $g_oCtx.beginPath() $g_oCtx.lineWidth = "3" $g_oCtx.strokeStyle = "green" $g_oCtx.moveTo(185, 85) $g_oCtx.lineTo(215, 115) $g_oCtx.stroke() ; Waiting for user to close the window While GUIGetMsg() <> $GUI_EVENT_CLOSE Sleep(10) WEnd GUIDelete() EndFunc ; ====================================================================================================== ; IE Event Functions - React to Mouse events with some Canvas graphics ; ====================================================================================================== #Region IE_EVENT_FUNCS ; For right-click, the context menu pops up, UNLESS we change the Event's 'returnValue' property Volatile Func Event_oncontextmenu($oEvtObj) If IsObj($oEvtObj) Then ; Convert to string so that 0 doesn't match EVERY string Local $sId = $oEvtObj.srcElement.id & "" If ($sId = "myCanvas") Then $oEvtObj.returnValue = False EndIf EndFunc Volatile Func Event_onmousedown($oEvtObj) If IsObj($oEvtObj) And IsObj($g_oCtx) Then ; Map click coordinates to Canvas coordinates $iLastX1 = $oEvtObj.x - $g_oCanvas.offsetLeft $iLastY1 = $oEvtObj.y - $g_oCanvas.offsetTop ;~ ConsoleWrite("Downclick recvd at X1: " & $iLastX1 & ", Y1: " & $iLastY1 & ", MouseButton [1 = left, 2 = right, etc] = " & $oEvtObj.button & @CRLF) ; Check if click was in fact within Canvas element If $iLastX1 >= 0 And $iLastX1 < $g_oCanvas.width And $iLastY1 >= 0 And $iLastY1 < $g_oCanvas.height Then ; Signal mouse-down occurred inside Canvas $bMouseDown = 1 ; Make a small square where initial down-click was detected $g_oCtx.fillStyle = "blue" $g_oCtx.fillRect($iLastX1 - 2, $iLastY1 - 2, 3, 3) EndIf EndIf EndFunc Volatile Func Event_onmouseup($oEvtObj) If IsObj($oEvtObj) And IsObj($g_oCtx) Then ;~ ConsoleWrite("MouseUp" & @LF) If $bMouseDown Then Local $iX = $oEvtObj.x - $g_oCanvas.offsetLeft, $iY = $oEvtObj.y - $g_oCanvas.offsetTop ; Random color in "#0f1100" (RGB) string form Local $sColor = "#" & Hex(Random(0, 255, 1), 2) & Hex(Random(0, 255, 1), 2) & Hex(Random(0, 255, 1), 2) ;; Draw either a line or circle depending on where the mouse button is released If $iX = $iLastX1 And $iY = $iLastY1 Then ; Circle if mouse start = mouse end $g_oCtx.beginPath() $g_oCtx.arc($iX, $iY, 8, 0, ACos(-1) * 2) $g_oCtx.fillStyle = $sColor $g_oCtx.fill() Else ; Line if mouse start <> mouse end $g_oCtx.beginPath() $g_oCtx.lineWidth = "3" $g_oCtx.strokeStyle = $sColor $g_oCtx.moveTo($iLastX1, $iLastY1) $g_oCtx.lineTo($iX, $iY) $g_oCtx.stroke() EndIf $bMouseDown = 0 EndIf EndIf EndFunc Volatile Func Event_onkeydown($oEvtObj) If IsObj($oEvtObj) Then ConsoleWrite("Event type: " & $oEvtObj.type & "id (0 is document) = " & $oEvtObj.srcElement.id) ConsoleWrite(", keycode = " & $oEvtObj.keyCode & ", shiftkey = " & $oEvtObj.shiftKey & @CRLF) EndIf EndFunc ; ====================================================================================================== #EndRegion IE_EVENT_FUNCS #EndRegion IE_CANVAS_EXAMPLE #Region UTIL_FUNCS ; ====================================================================================================== ; Func _ReRunIfNotElevated() ; ; Does what it says. (rumored to occasionally say what it does) ; ; Author: Ascend4nt ; ====================================================================================================== Func _ReRunIfNotElevated() If IsAdmin() Then Return 0 Else If @Compiled Then ; If compiled to A3X, we need to execute it as if not compiled. Local $sCmd = (@AutoItExe = @ScriptFullPath) ? "" : ("/AutoIt3ExecuteScript " & @ScriptFullPath) Return ShellExecute(@AutoItExe, $sCmd, @ScriptDir, "runas") Else Return ShellExecute(@AutoItExe,@ScriptFullPath,@ScriptDir,"runas") EndIf EndIf EndFunc #EndRegion UTIL_FUNCS IEEmbeddedVersioning.zip ~prev Downloads: 61 Also, HTML5+Javascript standalone Canvas demo (should run in any browser): HTML5StandaloneCanvasDemo.zip
    1 point
  3. Maybe Local $s = FileRead("File.bat") ;....code FileWrite("File_.bat", $res) ?
    1 point
  4. What exactly is not correct with the latest script?
    1 point
  5. Is that better? Local $s = "@echo off" & @CRLF & "echo Hello World %asdas%" Local $a = StringSplit($s, @CRLF, 3) For $i = 0 To UBound ($a) - 1 $a[$i] = Execute('"' & StringRegExpReplace($a[$i], "((?<!:|%)[[:alpha:]]++(?!%))", '" & _LetterIdx("' & '\1' & '") & "') & '"') Next Local $res = _ArrayToString($a, @CRLF) ConsoleWrite($res & @LF) Func _LetterIdx($str) Local $a = StringToASCIIArray(StringLower($str)) For $i = 0 To UBound($a) - 1 $a[$i] = "%chrset:~" & ($a[$i] - Asc('a')) & ", 1%" Next Return(_ArrayToString($a, "")) EndFunc
    1 point
  6. I'm slowly getting it now: you whish to replace every letter within words not preceeded by : or not enclosed by % by the string "%chrset:~" concatenated with the index of the letter starting with a = 1 then concatenated with ", 1%". BTW, there are 26 letters in a-z not 24 and how should we encode spaces, @ and other non-letters? In other words: what are you trying to achieve? Is that some way of re-encoding commands into another codepage? This is what I can do with your specifications as you exposed them: Local $s = "@echo off" & @CRLF & "echo Hello World %asdas%" Local $a = StringSplit($s, @CRLF, 3) For $i = 0 To UBound ($a) - 1 $a[$i] = Execute('"' & StringRegExpReplace($a[$i], "((?<!:|%)[@[:alpha:]]++(?!%)\h*)", '" & _LetterIdx("' & '\1' & '") & "') & '"') Next Local $res = _ArrayToString($a, @CRLF) ConsoleWrite($res & @LF) Func _LetterIdx($str) Local $a = StringToASCIIArray(StringLower($str)) For $i = 0 To UBound($a) - 1 $a[$i] = "%chrset:~" & ($a[$i] - Asc('a') + 1) & ", 1%" Next Return(_ArrayToString($a, "")) EndFunc Notice how @ and spaces are translated into negative values...
    1 point
  7. Does this work for you? Local $s = "@echo off" & @CRLF & "echo Hello World %asdas%" Local $res = StringRegExpReplace($s, "(?m)((?<!:|%)[@[:alpha:]]++(?!%)\h*)", "%chrset:~X, 1%") ConsoleWrite($res & @LF) BTW how can the output serve any purpose?
    1 point
  8. If I understand you correctly you need to replace every word not enclosed with either % or : by a fixed string. But what does X = 0-24 mean?
    1 point
  9. Danyfirex

    Guitar Tab Tester

    Hi all, last night I was playing with >MIDI UDF by Ascend4nt, and thought about making a game to learn the notes on the fretboard of the guitar (in the final I did not the game) but I made a guitar tablature tester. (Maybe I I add the game later.) Functions. Play notes. Play notes. while MouseDown+MouseMove Play Tabs. Change Speed. Highlight Note. Note: The tab file are into the tabs folder (see the file format if you want add more tabs) It does not supports sound effects as (slide,bend,pull off) Only clean notes. Update Version 0.1.3 (02/03/2014) Latest version! Version 0.1.3 (02/03/2014) Changed: _PlayTab Funcion rewritten Added: Play/Stop while Tab is sounding Added: Change Timing while Tab is sounding Added: Number Fret marks Added: Some tabs Guitar Tab Tester 0.1.3.rar Update Version 0.1.2 (18/02/2014) Older version! Version 0.1.2 (18/02/2014) Fixed: Notes up 9 fret Doesn't Sound Fixed: Notes Highlighting Added: English Notation Added: Some tabs Changed: GUI Look Changed: Code Structure Guitar Tab Tester 0.1.2.rar Capture: Well I hope You understand it was a hard fight vs Google traslate. (sorry for my English) suggestions, criticism, comments, help are wellcome. Saludos
    1 point
  10. Can you try to make your specification more precise please?
    1 point
  11. Melba23

    Embedded Video Player

    CodingCody37, That is only trancexx's personal opinion - I and many others, on the other hand, believe Au3Check to be valuable tool to prevent basic coding errors. Admittedly the utility can have problems with some of the more esoteric AutoIt syntax, but if you point out the problem to those who maintain it (Jos and jpm), it can often be fixed. Overall it is a good thing to have in your tool box, as long as you realise it, along with most things, is not infallible. M23
    1 point
  12. MHz

    CMenu

    CMenu v2.6 CMenu is a handy, context menu extension. Adds a branch to your context menu called More Options. Uses PEiD, which is able to recognize installer types, if available in it's the database. Identify Installer uses this information, and is able to popup a window to show parameters associated with that installer. Identify Installer can unpack, admin, record, silent installations, if available. And also create a template AutoIt Script, to suit.Includes CMenu Editor. This allows further customizing.Files can Execute With Parameters, optional working directory, and allowing for different window states.Create a Directory List. Preset options are available, as well as a custom options.Create an AutoIt Archive Script, that can be included into your main scripts. This allows AutoIt to act like an archiver.Includes PEiD as a separate item also, which allows the user to enhanced, portable executable identification.Filenames and paths can be easily sent to the windows clipboard, by using Path To ClipBoard.Allows for the user to download and add Resource Hacker or Stud PE. These will be detected, if placed in the correct folder, and will be added to the context menu.MyUninstaller is included in CMenu, with little overhead to size.Force Delete is included in CMenu. Use this only, as required. When deleting multiple files, do not do anything, until the operation is complete. A msgbox will popup and will allow, not to proceed. Use at own risk. A msgbox will popup and will allow, not to proceed. Use at own risk.AutoItMacroGenerator is included to handle recording AutoIt scripts for unidentified installers. Reg2Au3 quickly converts Regedit4 exported files into AutoIt3 syntax.Ini2Au3 quickly converts Ini files into AutoIt syntax. Constants Generator retrieves the constants declarations that your AutoIt script only needs. 7-Zip2Sfx for easily converting 7z archives to self extracting archives.A project, that I have been working on. Try it out, and see if it is usefull for you. Any feedback on any bugs or compliments would be appreciated. Enjoy CMenu Homepage >>>>> Download Here <<<<< ( 1.50 Mb ) P.S. It is an exe format. But can be freely decompiled with Aut2Exe. Also can have all source files, extracted to @ScriptDir, by using CMenu.exe /extract When installed, you will see CMenu as More Options in your contextmenu. A help guide is supplied to help you with this time saving program. It uses Latest AutoIt v3.2.0.1. Edit: Updated link to a new homepage. Old homepage link does not exist anymore.
    1 point
  13. This works, as I am guessing you already know about _ArrayAdd() and were just thinking outside the box. Good for you. #include <Array.au3> Local $aArray[1024] Local $iIndex = -1 PostIncrement($iIndex) $aArray[$iIndex] = "Start" For $i = 1 To 10 PostIncrement($iIndex) $aArray[$iIndex] = "New Value" Next PostIncrement($iIndex) $aArray[$iIndex] = "End" _ArrayDisplay($aArray) Func PostDecrement(ByRef $iValue) $iValue -= 1 Return $iValue EndFunc ;==>PostDecrement Func PostIncrement(ByRef $iValue) $iValue += 1 Return $iValue EndFunc ;==>PostIncrement
    1 point
  14. I have been trying to get your script to work, but I have had no luck. Apparently, Word's clipboard is separate from the operating system. I thought if there were some kind of shortcut key to perform this function in Word, then that could be a solution. I found a pdf that shows all shortcut keys in Word, but there is none to clear the clipboard. Sorry, but I don't see any way to accomplish your task.
    1 point
  15. Use Random() to create an index of the list number and then process. So I will demonstrate with an array. #include <MsgBoxConstants.au3> Local $aList = [100, 200, 300, 99] Local $iIndex = Random(0, UBound($aList) - 1, 1) MsgBox($MB_SYSTEMMODAL, '', $aList[$iIndex])
    1 point
  16. LarsJ

    TriSpiral - A work in Progress

    Here's a suggestion for a solution. The examples show how the spirals are created. Spirals.7z
    1 point
  17. Nearly there, the position of the outer spirals needs adjusting. #include <GuiConstantsEx.au3> #include <GDIPlus.au3> #include <Math.au3> Global Const $width = 800 Global Const $height = 800 Global Const $Black = "0xFF000000" Global Const $White = "0xFFFFFFFF" Global Const $Red = "0xFFFF0000" Global Const $Green = "0xFF00FF00" Global Const $Blue = "0xFF0000FF" Global Const $Yellow = "0xFFFFFF00" Global Const $Gray = "0xFFdfdcd6" Global $Dot_Size = 4 Global $XOrigin, $YOrigin, $Size, $Stp, $OuterXorg1, $Outeryorg1 Global $title = "Spirals" Global Const $nPI = 3.1415926535897932384626433832795 Global $hGUI, $hWnd, $hGraphic ; Create GUI $hGUI = GUICreate($title, $width, $height) $hWnd = WinGetHandle($title) GUISetState() _GDIPlus_Startup () $hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hWnd) $hPenBlk = _GDIPlus_PenCreate ($Black) $hPenWht = _GDIPlus_PenCreate ($White,4) $hPenBlue = _GDIPlus_PenCreate ($Blue) $hPenGrn = _GDIPlus_PenCreate ($Green) $hBrushWht = _GDIPlus_BrushCreateSolid($White) $OrgX = $Width/2 $OrgY = $Height/2 $Size = 150 ControlFocus("Spirals","","") ;--------------------------- Draw Spirals ------------------------------------ ; Spiral 1 $Stp = 3 ; <<--------- Defines the smoothness and the size of the Sprial, Smaller value = larger Spiral ------- $Size = 0 For $R = 0 to 360 *5 step $Stp $Rad = _Radian ($R) $X = Sin($Rad)*$Size + $OrgX $Y = Cos($Rad)*$Size + $OrgY ; _GDIPlus_GraphicsDrawEllipse($hGraphic, $X - $Dot_Size/2, $Y - $Dot_Size/2 , $Dot_Size, $Dot_Size, $hPenBlk) ; _GDIPlus_GraphicsFillEllipse($hGraphic, $X - $Dot_Size/2, $Y - $Dot_Size/2 ,$Dot_Size , $Dot_Size, $hBrushWht) $R1 = $R + $Stp $Rad1 = _Radian ($R1) $Px = Sin($Rad1)*$Size + $OrgX $Py = Cos($Rad1)*$Size + $OrgY _GDIPlus_GraphicsDrawLine ($hGraphic,$X,$Y,$Px,$Py,$hPenBlk) ; _GDIPlus_GraphicsDrawLine ($hGraphic,$OrgX,$OrgY,$Px,$Py,$hPenBlk) $Size += 0.3 _SlowDraw() ; looks nicer if you slow the drawing down Next ;_Pause() ; ** Outer Spiral 1 ** $OuterSize = 90 $Start = 180 $Size = 90 $Stp = 2 $OuterXorg1 = $Px $OuterYOrg1 = $Py + $OuterSize For $R = $Start + 360 * 5 to $Start step -$Stp $Rad = _Radian ($R) $X = Sin($Rad)*$OuterSize + $OuterXorg1 $Y = Cos($Rad)*$OuterSize + $OuterYOrg1 ; _GDIPlus_GraphicsDrawEllipse($hGraphic, $X - $Dot_Size/2, $Y - $Dot_Size/2 , $Dot_Size, $Dot_Size, $hPenBlk) ; _GDIPlus_GraphicsFillEllipse($hGraphic, $X - $Dot_Size/2, $Y - $Dot_Size/2 ,$Dot_Size , $Dot_Size, $hBrushWht) $R1 = $R + $Stp $Rad1 = _Radian ($R1) $Px = Sin($Rad1)*$OuterSize + $OuterXorg1 $Py = Cos($Rad1)*$OuterSize + $OuterYOrg1 _GDIPlus_GraphicsDrawLine ($hGraphic,$X,$Y,$Px,$Py,$hPenBlk) ; _GDIPlus_GraphicsDrawLine ($hGraphic,$OrgX,$OrgY,$Px,$Py,$hPenBlk) $OuterSize -= 0.09 _SlowDraw() ; looks nicer if you slow the drawing down Next ; Spiral 2 $Stp = 3 $Size = 0 $Start = 180 For $R = $Start to ($Start *10)+ $Start step $Stp $Rad = _Radian ($R) $X = Sin($Rad)*$Size + $OrgX $Y= Cos($Rad)*$Size + $OrgY $R1 = $R + $Stp $Rad1 = _Radian ($R1) $Px = Sin($Rad1)*$Size + $OrgX $Py = Cos($Rad1)*$Size + $OrgY _GDIPlus_GraphicsDrawLine ($hGraphic,$X,$Y,$Px,$Py,$hPenBlue) ; _GDIPlus_GraphicsDrawLine ($hGraphic,$X,$Y,$Px,$Py,$hPenBlk) $Size += 0.3 _SlowDraw() ; looks nicer if you slow the drawing down Next ;_Pause() ; *** Outer Spiral 2 *** $OuterSize = 90 $Start = 0 $Stp = 2 $OuterXorg1 = $Px $OuterYOrg1 = $Py - $OuterSize For $R = $Start + 360 * 5 to $Start step -$Stp $Rad = _Radian ($R) $X = Sin($Rad)*$OuterSize + $OuterXorg1 $Y = Cos($Rad)*$OuterSize + $OuterYOrg1 ; _GDIPlus_GraphicsDrawEllipse($hGraphic, $X - $Dot_Size/2, $Y - $Dot_Size/2 , $Dot_Size, $Dot_Size, $hPenBlk) ; _GDIPlus_GraphicsFillEllipse($hGraphic, $X - $Dot_Size/2, $Y - $Dot_Size/2 ,$Dot_Size , $Dot_Size, $hBrushWht) $R1 = $R + $Stp $Rad1 = _Radian ($R1) $Px = Sin($Rad1)*$OuterSize + $OuterXorg1 $Py = Cos($Rad1)*$OuterSize + $OuterYOrg1 _GDIPlus_GraphicsDrawLine ($hGraphic,$X,$Y,$Px,$Py,$hPenBlue) ; _GDIPlus_GraphicsDrawLine ($hGraphic,$OrgX,$OrgY,$Px,$Py,$hPenBlk) $OuterSize -= 0.09 _SlowDraw() ; looks nicer if you slow the drawing down Next ;Spiral 3 $Size = 0 $Stp = 3 $Start = 270 For $R = $Start to ($Start * 6.65) + $Start step $Stp $Rad = _Radian ($R) $X = Sin($Rad)*$Size + $OrgX $Y= Cos($Rad)*$Size + $OrgY $R1 = $R + $Stp $Rad1 = _Radian ($R1) $Px = Sin($Rad1)*$Size + $OrgX $Py = Cos($Rad1)*$Size + $OrgY _GDIPlus_GraphicsDrawLine ($hGraphic,$X,$Y,$Px,$Py,$hPenWht) ; _GDIPlus_GraphicsDrawLine ($hGraphic,$OrgX,$OrgY,$Px,$Py,$hPenBlue) $Size += 0.3 _SlowDraw() ; looks nicer if you slow the drawing down Next ; **** Outer Spiral 3 **** $OuterSize = 90 $Start = 90 $Stp = 2 $OuterXorg1 = $Px - $OuterSize $OuterYOrg1 = $Py For $R = $Start + 360 * 5 to $Start step -$Stp $Rad = _Radian ($R) $X = Sin($Rad)*$OuterSize + $OuterXorg1 $Y = Cos($Rad)*$OuterSize + $OuterYOrg1 ; _GDIPlus_GraphicsDrawEllipse($hGraphic, $X - $Dot_Size/2, $Y - $Dot_Size/2 , $Dot_Size, $Dot_Size, $hPenBlk) ; _GDIPlus_GraphicsFillEllipse($hGraphic, $X - $Dot_Size/2, $Y - $Dot_Size/2 ,$Dot_Size , $Dot_Size, $hBrushWht) $R1 = $R + $Stp $Rad1 = _Radian ($R1) $Px = Sin($Rad1)*$OuterSize + $OuterXorg1 $Py = Cos($Rad1)*$OuterSize + $OuterYOrg1 _GDIPlus_GraphicsDrawLine ($hGraphic,$X,$Y,$Px,$Py,$hPenWht) ; _GDIPlus_GraphicsDrawLine ($hGraphic,$OrgX,$OrgY,$Px,$Py,$hPenBlk) $OuterSize -= 0.09 _SlowDraw() ; looks nicer if you slow the drawing down Next Func _SlowDraw() Sleep(5) EndFunc Func _Pause() msgbox(0,"", "Done") ;_GDIPlus_GraphicsClear($hGraphic ,$Gray) EndFunc ; Loop until user exits Do Until GUIGetMsg() = $GUI_EVENT_CLOSE ; Clean up resources _GDIPlus_GraphicsDispose ($hGraphic) _GDIPlus_PenDispose($hPenBlk) _GDIPlus_PenDispose($hPenWht) _GDIPlus_PenDispose($hPenBlue) _GDIPlus_PenDispose($hPenGrn) _GDIPlus_BrushDispose($hBrushWht) _GDIPlus_Shutdown ()
    1 point
  18. I forgot to mention a configuration I am using. To prevent DNS leaks it is recommended to disable IPv6. The following registry key will disable IPv6 in Windows 7. Copy this code into a "New Text Document.txt" and rename it to "DisableIPv6.reg" Run it and reboot. Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\TCPIP6\Parameters] "DisabledComponents"=dword:ffffffff
    1 point
  19. The GDI+ v1.1 built-in blur code is too slow and the effect doesn't look very well at least on my Win 8.1 notebook. I changed the code a little bit using the blur code from eukalyptus and added an option to blur-in (by default not enabled) the image. The code doesn't require GDI+ v1.1 and should run also on WinXP (not tested). #include <GDIPlus.au3> #include <WindowsConstants.au3> _GDIPlus_Startup() MessageBoxBlurBackground("Is this what you are looking for?") _GDIPlus_Shutdown() Func MessageBoxBlurBackground($sText, $sHeader = "Question", $iFlag = 4 + 32 + 262144, $fBlur = 0.15, $bBlurIn = False, $iTimeOut = 0) ;coded by UEZ Local $hFullScreen = WinGetHandle("[TITLE:Program Manager;CLASS:Progman]"), $aFullScreen = WinGetPos($hFullScreen) Local Const $iW = $aFullScreen[2], $iH = $aFullScreen[3] Local $hGui = GUICreate("", $iW, $iH, $aFullScreen[0], $aFullScreen[1], $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_APPWINDOW)) Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui) ;capture full screen Local $hWnd = _WinAPI_GetDesktopWindow() Local $hDDC = _WinAPI_GetDC($hWnd) Local $hCDC = _WinAPI_CreateCompatibleDC($hDDC) Local $hHBitmap = _WinAPI_CreateCompatibleBitmap($hDDC, $iW, $iH) _WinAPI_SelectObject($hCDC, $hHBitmap) _WinAPI_BitBlt($hCDC, 0, 0, $iW, $iH, $hDDC, $aFullScreen[0], $aFullScreen[1], $SRCCOPY) ;copy captured screen to bitmap _WinAPI_ReleaseDC($hWnd, $hDDC) _WinAPI_DeleteDC($hCDC) Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hHBitmap) ;convert GDI bitmap to GDI+ bitmap _WinAPI_DeleteObject($hHBitmap) Local $hBmp_GDIPlus_BitmapBlurred, $i Switch $bBlurIn Case True GUISetState(@SW_SHOWNA) For $i = 2 To 7 Step 0.5 $hBmp_GDIPlus_BitmapBlurred = _GDIPlus_BitmapBlur($hBitmap, $iW, $iH, 1 / $i) _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBmp_GDIPlus_BitmapBlurred, 0, 0, $iW, $iH) ;copy blurred image to GUI _GDIPlus_BitmapDispose($hBmp_GDIPlus_BitmapBlurred) Next Case Else $hBmp_GDIPlus_BitmapBlurred = _GDIPlus_BitmapBlur($hBitmap, $iW, $iH, $fBlur) GUISetState(@SW_SHOWNA) _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBmp_GDIPlus_BitmapBlurred, 0, 0, $iW, $iH) ;copy blurred image to GUI _GDIPlus_BitmapDispose($hBmp_GDIPlus_BitmapBlurred) EndSwitch Local $iRet = MsgBox($iFlag, $sHeader, $sText, $iTimeOut, $hGui) ;cleanup resources _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_GraphicsDispose($hGraphics) GUIDelete($hGui) Return $iRet EndFunc Func _GDIPlus_BitmapBlur($hBitmap, $iW, $iH, $fScale = 0.15, $qual = 6); by eukalyptus Local Const $hGraphics = _GDIPlus_GraphicsCreateFromHWND(_WinAPI_GetDesktopWindow()) Local Const $hBmpSmall = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hGraphics) Local Const $hGfxSmall = _GDIPlus_ImageGetGraphicsContext($hBmpSmall) _GDIPlus_GraphicsSetPixelOffsetMode($hGfxSmall, $GDIP_PIXELOFFSETMODE_HIGHQUALITY) Local Const $hBmpBig = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hGraphics) Local Const $hGfxBig = _GDIPlus_ImageGetGraphicsContext($hBmpBig) _GDIPlus_GraphicsSetPixelOffsetMode($hGfxBig, $GDIP_PIXELOFFSETMODE_HIGHQUALITY) _GDIPlus_GraphicsScaleTransform($hGfxSmall, $fScale, $fScale) _GDIPlus_GraphicsSetInterpolationMode($hGfxSmall, $qual) _GDIPlus_GraphicsScaleTransform($hGfxBig, 1 / $fScale, 1 / $fScale) _GDIPlus_GraphicsSetInterpolationMode($hGfxBig, $qual) _GDIPlus_GraphicsDrawImageRect($hGfxSmall, $hBitmap, 0, 0, $iW, $iH) _GDIPlus_GraphicsDrawImageRect($hGfxBig, $hBmpSmall, 0, 0, $iW, $iH) _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_BitmapDispose($hBmpSmall) _GDIPlus_GraphicsDispose($hGfxSmall) _GDIPlus_GraphicsDispose($hGfxBig) Return $hBmpBig EndFunc ;==>_GDIPlus_BitmapBlur Br, UEZ
    1 point
  20. LAST VERSION - 2.2 14-Mar-10 3D Axis is designed to draw graphs of almost any trigonometric functions that can be specified as a single function - f(a,b). The functions can be specified in one of the three coordinate systems: cartesian, cylindrical or spherical. By default, you can use any functions that are defined in AutoIt (Cos(), Sin(), Sqrt() etc.), but you can also import your own functions, for example write a function for Fourier series. At the beginning, try to play with the examples that appear below (Examples.3da). Just drag this file to the main program window, select any graphs, and click "Draw" button. But do not draw all graphs at once, as this may take a long time. Try to come up with their own functions, it all depends on your imagination. If anyone got beautiful graphs, please post it in this thread (better in .3da file). 3D Axis has one drawback - size of the main program window is more than 1250x860 and can not be resized that will fit not for all monitors! Therefore, recommended minimum size of your monitor should be 17". The any questions or comments about 3D Axis please post it in this thread. I will be glad to any feedback and suggestions. Files to download Binary Redirection to 3DAxis_bin.zip, 1.11 MB 3DAxis_bin.html Binary (GUI smaller version, size of the client area - 1101x733) Redirection to 3DAxis_small_bin.zip, 1.11 MB 3DAxis_small_bin.html Source Redirection to 3DAxis_source.zip, 668 KB 3DAxis_source.html Examples To draw graphs of the functions from the Examples.3da, just import or drag and drop this file into the program. Examples.zip
    1 point
  21. I've written some code for AutoIt that enables users to create objects from servers (dll-s) without the need to do any kind of registration manually. I didn't document it back then so likely you won't find any references. To use it, you would do something like this: Global Const $sCLSID_Mail = "{DF8A4FE2-221A-4504-987A-3FD4720DB929}" Global $hDLL = DllOpen("EASendMailObj.dll") ; path to the dll ; Create object $oObj = ObjCreate($sCLSID_Mail, Default, $hDLL) ; Do things with the object... ConsoleWrite("Date thingy = " & $oObj.Date & @CRLF) $oObj.BodyText = "Test Body" ;... Does that work for you? Oh and you need beta AutoIt for that.
    1 point
  22. #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
    1 point
×
×
  • Create New...