Leaderboard
Popular Content
Showing content with the highest reputation on 11/10/2021 in all areas
-
Currently the Active Directory UDF comes with two different types of help files: <functionname>.htm (example: _AD_Open.htm): HTML file for each function of the UDF. AD.htm: Single HTML file generated by HTMHelp for all functions of the UDF. With the help of MrCreator's "Simple Library Docs Generator" I was able to create a CHM file. This looks like the CHM help file provided with AutoIt. You still can't use this help file from SciTE but at least you get the same look and feel as the AutoIt help file ability to search the full help file With the next release of the AD UDF I plan to replace all current help files with the new CHM help file. Edit: Done. Please download the AD UDF version 1.6.0.0 or newer to get the latest CHM help file (for download please have a look at my signature below). Could you please have a look at the attached CHM help file and tell me what you think?2 points
-
Extended Message Box - New Version: 16 Feb 24
hudsonhock reacted to Melba23 for a topic
Are you annoyed by the limitations of the standard Windows message dialog created by MsgBox? Would you like to have coloured backgrounds and text? To choose the justification and font? Do you want to be able to place the message box other than in the centre of the screen? Centred on your GUI, for example, or at a particular location on screen? What about having user-defined text on as many buttons as you need? And user-defined icons? Or a visible countdown of the timeout? Finally, would you like to choose whether the message box has a button on your already too-crowded taskbar? If the answer to any of these questions is "YES" then the ExtMsgBox UDF is for you! [NEW VERSION] 16 Feb 24 Changed: Some additional functionality added to the "TimeOut" parameter of _ExtMsgBox: - A positive integer sets the EMB timeout as before. - A negative integer will double the size of the countdown timer if it is used. - A colon-delimited string (eg: "10:5") will set the normal EMB timeout (first integer) and will also initially disable the EMB buttons for the required period (second integer). New UDF and examples in the zip. Older version changes: ChangeLog.txt As always, I realise nearly all of the DLL calls in these UDFs could be made by using commands in other UDFs like WinAPI.au3 - but as with all my UDFs (which you can find in my sig below) I am trying to prevent the need for any other include files. The UDF and examples (plus StringSize) in zip format: ExtMsgBox.zip Courteous comments and constructive criticisms welcome - guess which I prefer! M231 point -
_Excel_BookOpenText Examples
SkysLastChance reacted to water for a topic
Make sure there is no instance of Excel running in the Task Manager after your script has ended. _Excel_Open always tries to connect tio an existing instance. Or set parameter $bForceNew to True for _:Excel_Open to make sure that a new instance gets started all the time.1 point -
Using UI Automation Code in AutoIt
junkew reacted to MightyWeird for a topic
Hi, I need some time to digest this.... Just wanted to thank you guys for taking your time.1 point -
word find chars like regexp
JockoDundee reacted to mikell for a topic
So did you try this ? "([0-9]*)[ ][ ]*"1 point -
Need help: How to set the variable to use the USER input.
It_is_me_Me reacted to Zedna for a topic
#include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GuiIPAddress.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GuiEdit.au3> #include <MsgBoxConstants.au3> #include <Date.au3> #include <TabConstants.au3> #include <GuiTab.au3> Global $Form1 = GUICreate("Security Automation", 490, 339, -1, -1) ;MAIN Tab Global $TAB = GUICtrlCreateTab(0, 0, 489, 337) Global $tab_main = GUICtrlCreateTabItem("Main") $label_Title = GUICtrlCreateLabel("ETP-073 Security", 12, 33, 103, 17) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") ;-----------------TCP User input information------------------------------------------------------------------------------- $groupBox_TCP = GUICtrlCreateGroup("TCP", 12, 49, 289, 57, BitOR($GUI_SS_DEFAULT_GROUP,$BS_FLAT)) ;TCP IP address Global $IPAddress1 = _GUICtrlIpAddress_Create($Form1, 20, 81, 170, 21) $Label_ipAddress = GUICtrlCreateLabel("Host IP Address", 20, 65, 80, 17) $userInputIP = _GUICtrlIpAddress_Set($IPAddress1, "0.0.0.0") ;TCP Port $label_tcpPort = GUICtrlCreateLabel("Port", 196, 65, 23, 17) Global $input_tcpPort = GUICtrlCreateInput("502", 196, 81, 57, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER)) ;TCP Address $label_tcpAddress = GUICtrlCreateLabel("Addr.", 260, 65, 29, 17) Global $input_tcpDevAddress = GUICtrlCreateInput("1", 260, 81, 33, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER)) ;Buttons Global $btn_userIP = GUICtrlCreateButton("User IP", 308, 297, 81, 25) Global $btn_Port = GUICtrlCreateButton("Port", 404, 297, 75, 25) ;Showing the GUI GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $btn_userIP $userIP = _GUICtrlIpAddress_Get($IPAddress1) ToolTip($userIP) Case $btn_Port $userPort = GUICtrlRead($input_tcpPort) ToolTip($userPort) EndSwitch WEnd1 point -
ControlCommand Failed to get state on Winform Platform - (Moved)
Wellwellwell reacted to Jos for a topic
Moved to the appropriate forum. Moderation Team1 point -
Maybe this helps https://stackoverflow.com/questions/11537103/how-to-handle-print-dialog-in-selenium1 point
-
$PropertyConditionFlags_MatchSubstring It's true that wildcards aren't supported. On the other hand, it's possible to search for substrings in string properties through the Windows 10 1809 update: ; enum PropertyConditionFlags Global Const $PropertyConditionFlags_None = 0 Global Const $PropertyConditionFlags_IgnoreCase = 1 Global Const $PropertyConditionFlags_MatchSubstring = 2 ; Windows 10-1809 To use the $PropertyConditionFlags_MatchSubstring constant, it's necessary to use a version of the UIA code that includes this Windows update. To do this, select the correct Windows Mode in UIASpy: Now the code generated automatically by UIASpy will look like this: #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ;#AutoIt3Wrapper_UseX64=n ; If target application is running as 32 bit code ;#AutoIt3Wrapper_UseX64=y ; If target application is running as 64 bit code #include "UIA_Constants.au3" ; Can be copied from UIASpy Includes folder ;#include "UIA_Functions.au3" ; Can be copied from UIASpy Includes folder ;#include "UIA_SafeArray.au3" ; Can be copied from UIASpy Includes folder ;#include "UIA_Variant.au3" ; Can be copied from UIASpy Includes folder Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Create UI Automation object Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation8, $sIID_IUIAutomation6, $dtag_IUIAutomation6 ) If Not IsObj( $oUIAutomation ) Then Return ConsoleWrite( "$oUIAutomation ERR" & @CRLF ) ConsoleWrite( "$oUIAutomation OK" & @CRLF ) ; Get Desktop element Local $pDesktop, $oDesktop $oUIAutomation.GetRootElement( $pDesktop ) $oDesktop = ObjCreateInterface( $pDesktop, $sIID_IUIAutomationElement9, $dtag_IUIAutomationElement9 ) If Not IsObj( $oDesktop ) Then Return ConsoleWrite( "$oDesktop ERR" & @CRLF ) ConsoleWrite( "$oDesktop OK" & @CRLF ) EndFunc ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition0 $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "Notepad", $pCondition0 ) If Not $pCondition0 Then Return ConsoleWrite( "$pCondition0 ERR" & @CRLF ) ConsoleWrite( "$pCondition0 OK" & @CRLF ) Local $pWindow1, $oWindow1 $oDesktop.FindFirst( $TreeScope_Children, $pCondition0, $pWindow1 ) $oWindow1 = ObjCreateInterface( $pWindow1, $sIID_IUIAutomationElement9, $dtag_IUIAutomationElement9 ) If Not IsObj( $oWindow1 ) Then Return ConsoleWrite( "$oWindow1 ERR" & @CRLF ) ConsoleWrite( "$oWindow1 OK" & @CRLF ) ; --- Element Properties --- ConsoleWrite( "--- Element Properties ---" & @CRLF ) Local $sName1 $oWindow1.GetCurrentPropertyValue( $UIA_NamePropertyId, $sName1 ) ConsoleWrite( "$sName1 = " & $sName1 & @CRLF ) In UIASpy, you generate the above code as follows: Sample code menu | Initial code | Complete code Click Notepad window in treeview to switch to info listview Right-click the $UIA_ClassNamePropertyId line | Create sample code Sample code menu | Properties ... | Right-click the $UIA_NamePropertyId line | Create sample code Right click code listview | Copy all items Paste the code into your editor Edit the code to make it runnable. And replace CreatePropertyCondition() with CreatePropertyConditionEx() to apply PropertyConditionFlags: #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ;#AutoIt3Wrapper_UseX64=n ; If target application is running as 32 bit code ;#AutoIt3Wrapper_UseX64=y ; If target application is running as 64 bit code #include "UIA_Constants.au3" ; Can be copied from UIASpy Includes folder ;#include "UIA_Functions.au3" ; Can be copied from UIASpy Includes folder ;#include "UIA_SafeArray.au3" ; Can be copied from UIASpy Includes folder ;#include "UIA_Variant.au3" ; Can be copied from UIASpy Includes folder Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Create UI Automation object Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation8, $sIID_IUIAutomation6, $dtag_IUIAutomation6 ) If Not IsObj( $oUIAutomation ) Then Return ConsoleWrite( "$oUIAutomation ERR" & @CRLF ) ConsoleWrite( "$oUIAutomation OK" & @CRLF ) ; Get Desktop element Local $pDesktop, $oDesktop $oUIAutomation.GetRootElement( $pDesktop ) $oDesktop = ObjCreateInterface( $pDesktop, $sIID_IUIAutomationElement9, $dtag_IUIAutomationElement9 ) If Not IsObj( $oDesktop ) Then Return ConsoleWrite( "$oDesktop ERR" & @CRLF ) ConsoleWrite( "$oDesktop OK" & @CRLF ) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition0 ;$oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "Notepad", $pCondition0 ) $oUIAutomation.CreatePropertyConditionEx( $UIA_ClassNamePropertyId, "Note", $PropertyConditionFlags_MatchSubstring, $pCondition0 ) If Not $pCondition0 Then Return ConsoleWrite( "$pCondition0 ERR" & @CRLF ) ConsoleWrite( "$pCondition0 OK" & @CRLF ) Local $pWindow1, $oWindow1 $oDesktop.FindFirst( $TreeScope_Children, $pCondition0, $pWindow1 ) $oWindow1 = ObjCreateInterface( $pWindow1, $sIID_IUIAutomationElement9, $dtag_IUIAutomationElement9 ) If Not IsObj( $oWindow1 ) Then Return ConsoleWrite( "$oWindow1 ERR" & @CRLF ) ConsoleWrite( "$oWindow1 OK" & @CRLF ) ; --- Element Properties --- ConsoleWrite( "--- Element Properties ---" & @CRLF ) Local $sName1 $oWindow1.GetCurrentPropertyValue( $UIA_NamePropertyId, $sName1 ) ConsoleWrite( "$sName1 = " & $sName1 & @CRLF ) EndFunc SciTE output: $oUIAutomation OK $oDesktop OK --- Find window/control --- $pCondition0 OK $oWindow1 OK --- Element Properties --- $sName1 = Untitled - Notepad Example 16 Example 16 includes the original CUIAutomation2.au3 created by junkew, which contains all the Windows 7 constants. In newer versions of the UIA code I use UIA_Constants.au3 which contains all Windows 7 constants as well as all constants added in Windows 8, 8.1 and 10. The reason for the error in your code is that both CUIAutomation2.au3 and UIA_Constants.au3 is included. Only UIA_Constants.au3 should be included. Example 16 is an old example from March 9, 2019. Unfortunately, it's not possible for me to update all examples every time I update the UIA code. And the Windows 7 code still works, unless you need the newer code added in later Windows versions. To close a window with UIA code, use the Close method of the IUIAutomationWindowPattern interface. See examples 2 and 3 in Patterns (actions). Note that these are also old examples from March 9, 2019. If the Close method doesn't work, you can e.g. try using the UIA_MouseClick() function, which almost always works. UIA_MouseClick() is found in two different UDFs: UIA_Functions.au3, which is the new version based on UIA_Constants.au3, and UIA_Functions-a.au3, which is the old version based on CUIAutomation2.au3. Use the new version. An obvious error in your code is that you use the UIA_MouseClick() function with a pattern (action) object as input parameter. The correct input parameter is a window or control (a UIA element) object. Only UIA elements can be clicked. Not patterns (actions).1 point
-
;$sServer = '192.168.42.228, 1500' ;try this: $sServer = '192.168.42.228' ;or use the server name as from the original example by Zedna, Aug 6, 2020 ;https://www.autoitscript.com/forum/topic/203542-ms-sql-connection/?do=findComment&comment=1461607 ;$sServer = 'server1' ;or try changing connection string: $DSN = 'SQLOLEDB;Data Source=' & $sServer & ';Initial Catalog=' & $sDatabase & ';User Id=' & $sUID &';Password=' & $sPWD & ';' See also: List all installed OLE DB providers: https://www.autoitscript.com/wiki/ADO_Tools A possible problem of your script is keeping open connections in presence of errors because of this: If @error Then Exit Better always checking for open connections on exit. This would be my version of your example: #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt("MustDeclareVars", 1) Opt("TrayIconDebug", 1) OnAutoItExitRegister("OnAutoItExit") Global $nMsg Global $oConn, $sSQL Global $sServer = '192.168.42.228' Global $sDatabase = 'tempdb' Global $sUID = 'sa' Global $sPWD = 'examplepass' #===== ADODB ===== ;Help: COM Error Handling ;_ErrADODB From spudw2k ;https://www.autoitscript.com/forum/topic/105875-adodb-example/ Global $errADODB = ObjEvent("AutoIt.Error","_ErrADODB") Global Const $iCursorType = 3 ;0 adOpenForwardOnly, 3 adOpenStatic Global Const $iLockType = 3 ;1 adLockReadOnly, 3 adLockOptimistic Global Const $iOptions = 1 ; Options, 1 Evaluates as a textual definition of a command or stored procedure call ; 2 adCmdTable $oConn = ObjCreate("ADODB.Connection") ; Create a connection object ;~ ;https://accessexperts.com/blog/2011/03/24/sql-server-connections-strings-for-microsoft-access/ ;~ ;You should bypass the ODBC layer altogether when connecting to SQL Sever by using a connection string similar to this one in your code: ;~ ;stConnect = "Provider=SQLOLEDB;Data Source=... ;~ ;Or if you’re using native client: ;~ ;stConnect = "Provider=SQLNCLI10;Data Source=... Global $sADOConnectionString = 'Provider=SQLOLEDB;Data Source=' & $sServer & ';Initial Catalog=' & $sDatabase & ';User Id=' & $sUID &';Password=' & $sPWD & ';' ;https://www.w3schools.com/asp/prop_rs_cursorlocation.asp ;A Recordset object inherits this setting from the associated Connection object. ;This property is read-only on an open Recordset object, and read/write on a Connection object or on a closed Recordset object. $oConn.CursorLocation = 2 ;2 adUseServer, 3 adUseClient $oConn.CommandTimeout = 10 ;https://stackoverflow.com/questions/31941487/open-adodb-connection-to-excel-file-in-read-only-mode ;https://www.w3schools.com/asp/prop_rec_mode.asp $oConn.Mode = 1 ;Read-only #Region ### START Koda GUI section ### Form= Global $Form1 = GUICreate("Form1", 384, 168, 192, 124) Global $connect_ = GUICtrlCreateButton("Connect", 144, 112, 91, 33) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $connect_ ms_sql_connection() EndSwitch WEnd Func ms_sql_connection() $oConn.Open($sADOConnectionString) ; Open the connection MsgBox(1, "Connection String", $oConn.ConnectionString) ;Zedna, Aug 7, 2020 ;https://www.autoitscript.com/forum/topic/203542-ms-sql-connection/?do=findComment&comment=1461671 ;simple select returns 1 value (1 column and 1 row: count() max() TOP 1) $sSQL = "SELECT 'Version: ' + @@VERSION + CHAR(13) + 'Language: ' + @@LANGUAGE + CHAR(13) + 'ServerName: ' + @@SERVERNAME;" MsgBox(0, "", $oConn.Execute($sSQL).Fields(0).Value) $oConn.Close ;Close the connection $oConn = 0 ;Release the connection object EndFunc Func _ErrADODB() Msgbox(0,"ADODB COM Error","We intercepted a COM Error !" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $errADODB.description & @CRLF & _ "err.windescription:" & @TAB & $errADODB.windescription & @CRLF & _ "err.number is: " & @TAB & hex($errADODB.number,8) & @CRLF & _ "err.lastdllerror is: " & @TAB & $errADODB.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $errADODB.scriptline & @CRLF & _ "err.source is: " & @TAB & $errADODB.source & @CRLF & _ "err.helpfile is: " & @TAB & $errADODB.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $errADODB.helpcontext, 5) Local $err = $errADODB.number If $err = 0 Then $err = -1 Local $sFilePath = @DesktopDir & "\error.txt" ;Open the file for write access. Local $hFileOpen = FileOpen($sFilePath, 2) ;If $hFileOpen = -1 Then ;MsgBox(0, "", "An error occurred when reading/writing the file.") ;EndIf FileWrite($hFileOpen, "ADODB COM Error" & Chr(1) & _ "err.description is: " & @TAB & $errADODB.description & Chr(1) & _ "err.windescription:" & @TAB & $errADODB.windescription & Chr(1) & _ "err.number is: " & @TAB & hex($errADODB.number,8) & Chr(1) & _ "err.lastdllerror is: " & @TAB & $errADODB.lastdllerror & Chr(1) & _ "err.scriptline is: " & @TAB & $errADODB.scriptline & Chr(1) & _ "err.source is: " & @TAB & $errADODB.source & Chr(1) & _ "err.helpfile is: " & @TAB & $errADODB.helpfile & Chr(1) & _ "err.helpcontext is: " & @TAB & $errADODB.helpcontext _ ) ;Close the handle returned by FileOpen. FileClose($hFileOpen) $oConn.Close $oConn = 0 Exit EndFunc Func OnAutoItExit() If IsObj($oConn) Then If $oConn.State > 0 Then $oConn.Close ;adStateOpen Close the connection $oConn = 0 ; Release the connection object EndIf EndFunc1 point
-
This is a new version of the server/client example above based on the FakeObj object. Again, FakeObj is passed to the client through a ROT-object. Here, FakeObj can handle strings, doubles, integers and arrays. Server.au3: #AutoIt3Wrapper_Au3Check_Parameters=-d -w- 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #AutoIt3Wrapper_UseX64=Y Opt( "MustDeclareVars", 1 ) #include <Array.au3> #include "AccVars.au3" #include "IRunningObjectTable.au3" Global $oError = ObjEvent("AutoIt.Error", "_ErrFunc") Example() Func Example() ConsoleWrite( "Code running on server ..." & @CRLF ) Local $tFakeObj, $oFakeObj $oFakeObj = _ObjectFromTag("__MyInterface_", "Data hresult(variant)", $tFakeObj) $oFakeObj.Data("Test string from Server .....") $oFakeObj.Data( 123.123 ) $oFakeObj.Data( 123 ) Local $aArray = [ 123, 123.123, "Server test string" ] $oFakeObj.Data( $aArray ) ; Create a default ROT-object (Dictionary object) Local $sDataTransferObject, $oDataTransferObject $oDataTransferObject = ROT_CreateDefaultObject( $sDataTransferObject ) ; Create Dictionary object Local $oDict = ObjCreate( "Scripting.Dictionary" ) $oDict.Item( "$oFakeObj" ) = $oFakeObj ; Add Dictionary object to ROT-object $oDataTransferObject.Add( "$oDict", $oDict ) ; Start the client script in a new process ConsoleWrite( @CRLF & "Code running on Client ..." & @CRLF ) RunWait( @AutoItExe & " /AutoIt3ExecuteScript Client.au3" & " " & $sDataTransferObject ) EndFunc Func __MyInterface_QueryInterface($pSelf, $pRIID, $pObj) Local $tStruct = DllStructCreate("ptr", $pObj) DllStructSetData($tStruct, 1, $pSelf) Return 0 ; $S_OK #forceref $pRIID EndFunc Func __MyInterface_AddRef($pSelf) Return 1 #forceref $pSelf EndFunc Func __MyInterface_Release($pSelf) Return 1 #forceref $pSelf EndFunc Func __MyInterface_Data($pSelf, $pVariant) ConsoleWrite( @CRLF & "$pVar = " & $pVariant & @CRLF ) Local $tVariant = DllStructCreate( $tagVARIANT, $pVariant ) Local $sAlign1 = " " & ( @AutoItX64 ? " " : "" ) Local $iVariantType = DllStructGetData( $tVariant, "vt" ) ConsoleWrite( "Type = 0x" & Hex( $iVariantType, 4 ) & " " & $sAlign1 ) ; 4 word elements before the data element = 8 bytes Local $pData = $pVariant + 8, $tPtr, $pPtr Switch $iVariantType Case $VT_I4 ; 4 bytes signed integer ConsoleWrite( "(VT_I4, 4 bytes signed integer)" & @CRLF ) ; The data element contains the integer in the 4 first bytes Local $tInt = DllStructCreate( "int", $pData ) Local $iInt = DllStructGetData( $tInt, 1 ) ConsoleWrite( "data = " & $iInt & @CRLF ) Case $VT_R8 ; 8 bytes double ConsoleWrite( "(VT_R8, 8 bytes double)" & @CRLF ) ; The data element contains the double in the 8 first bytes ; That's the entire data element on 32 bit and half the data element on 64 bit Local $tFlt = DllStructCreate( "double", $pData ) Local $fFlt = DllStructGetData( $tFlt, 1 ) ConsoleWrite( "data = " & $fFlt & @CRLF ) Case $VT_BSTR ; Basic string ConsoleWrite( "(VT_BSTR, basic string)" & @CRLF ) ; The data element contains a pointer to the BSTR $tPtr = DllStructCreate( "ptr", $pData ) $pPtr = DllStructGetData( $tPtr, 1 ) ConsoleWrite( "pBSTR = " & $pPtr & " (BSTR pointer)" & @CRLF ) ; The BSTR must be read with a proper BSTR-function (see Variant.au3) Local $sStr = SysReadString( $pPtr ) ConsoleWrite( "data = " & $sStr & @CRLF ) Case $VT_ARRAY + $VT_VARIANT ; Array of variants ConsoleWrite( "(VT_ARRAY+VT_VARIANT, array of variants, safearray)" & @CRLF ) ; The data element contains a pointer to the safearray in the 4/8 first bytes $tPtr = DllStructCreate( "ptr", $pData ) $pPtr = DllStructGetData( $tPtr, 1 ) ConsoleWrite( "data = " & $pPtr & " (pointer to safearray)" & @CRLF ) ; Print safearray data to console ConsoleWrite( @CRLF & "Safearray data:" & @CRLF ) PrintSafeArray1D( $pPtr ) ; Convert safearray to AutoIt array through internal COM conversions ; Display the AutoIt array with _ArrayDisplay( $aArray ) ConsoleWrite( @CRLF & "Convert safearray to AutoIt array" & @CRLF ) Local $aArray SafeArrayLock( $pPtr ) AccessVariables02( AccVars_SafeArrayToArray, $pPtr, $aArray ) SafeArrayUnlock( $pPtr ) ConsoleWrite( "_ArrayDisplay( <AutoIt array> ) ..." & @CRLF ) _ArrayDisplay( $aArray ) Case Else ConsoleWrite( "Variant type = " & DllStructGetData( $tVariant, "vt" ) & @CRLF ) ConsoleWrite( "Unhandled variant type" & @CRLF ) EndSwitch Return 0 ; $S_OK #forceref $pSelf EndFunc ; #FUNCTION# ============================================================================= ; Name...........: _ObjectFromTag ; ======================================================================================== Func _ObjectFromTag($sFunctionPrefix, $tagInterface, ByRef $tInterface, $fPrint = False, $bIsUnknown = Default, $sIID = "{00000000-0000-0000-C000-000000000046}") ; last param is IID_IUnknown by default If $bIsUnknown = Default Then $bIsUnknown = True Local $sInterface = $tagInterface ; copy interface description Local $tagIUnknown = "QueryInterface hresult(ptr;ptr*);" & _ "AddRef dword();" & _ "Release dword();" ; Adding IUnknown methods If $bIsUnknown Then $tagInterface = $tagIUnknown & $tagInterface ; Below line is really simple even though it looks super complex. It's just written weird to fit in one line, not to steal your attention Local $aMethods = StringSplit(StringReplace(StringReplace(StringReplace(StringReplace(StringTrimRight(StringReplace(StringRegExpReplace(StringRegExpReplace($tagInterface, "\w+\*", "ptr"), "\h*(\w+)\h*(\w+\*?)\h*(\((.*?)\))\h*(;|;*\z)", "$1\|$2;$4" & @LF), ";" & @LF, @LF), 1), "object", "idispatch"), "hresult", "long"), "bstr", "ptr"), "variant", "ptr"), @LF, 3) Local $iUbound = UBound($aMethods) Local $sMethod, $aSplit, $sNamePart, $aTagPart, $sTagPart, $sRet, $sParams, $hCallback ; Allocation $tInterface = DllStructCreate("int RefCount;int Size;ptr Object;ptr Methods[" & $iUbound & "];int_ptr Callbacks[" & $iUbound & "];ulong_ptr Slots[16]") ; 16 pointer sized elements more to create space for possible private props If @error Then Return SetError(1, 0, 0) For $i = 0 To $iUbound - 1 $aSplit = StringSplit($aMethods[$i], "|", 2) If UBound($aSplit) <> 2 Then ReDim $aSplit[2] $sNamePart = $aSplit[0] $sTagPart = $aSplit[1] $sMethod = $sFunctionPrefix & $sNamePart If $fPrint Then Local $iPar = StringInStr($sTagPart, ";", 2), $t If $iPar Then $t = "Ret: " & StringLeft($sTagPart, $iPar - 1) & " " & _ "Par: " & StringRight($sTagPart, StringLen($sTagPart) - $iPar) Else $t = "Ret: " & $sTagPart EndIf Local $s = "Func " & $sMethod & _ "( $pSelf ) ; " & $t & @CRLF & _ "EndFunc" & @CRLF ConsoleWrite($s) EndIf $aTagPart = StringSplit($sTagPart, ";", 2) $sRet = $aTagPart[0] $sParams = StringReplace($sTagPart, $sRet, "", 1) $sParams = "ptr" & $sParams $hCallback = DllCallbackRegister($sMethod, $sRet, $sParams) If @error Then ConsoleWrite('! ' & @error & ' ' & $sMethod & @CRLF & @CRLF) EndIf DllStructSetData($tInterface, "Methods", DllCallbackGetPtr($hCallback), $i + 1) ; save callback pointer DllStructSetData($tInterface, "Callbacks", $hCallback, $i + 1) ; save callback handle Next DllStructSetData($tInterface, "RefCount", 1) ; initial ref count is 1 DllStructSetData($tInterface, "Size", $iUbound) ; number of interface methods DllStructSetData($tInterface, "Object", DllStructGetPtr($tInterface, "Methods")) ; Interface method pointers Return ObjCreateInterface(DllStructGetPtr($tInterface, "Object"), $sIID, $sInterface, $bIsUnknown) ; pointer that's wrapped into object EndFunc ;==>ObjectFromTag Func _ErrFunc() ConsoleWrite("! COM Error ! Number: 0x" & Hex($oError.number, 8) & " ScriptLine: " & $oError.scriptline & " - " & $oError.windescription & @CRLF) Return EndFunc ;==>_ErrFunc Func PrintSafeArray1D( $pSafeArray ) If Not IsPtr( $pSafeArray ) Then Return SetError(1,0,0) If Not SafeArrayGetDim( $pSafeArray ) = 1 Then Return SetError(2,0,0) Local $tSafeArray = DllStructCreate( $tagSAFEARRAY, $pSafeArray ) Local $iElemSize = DllStructGetData( $tSAFEARRAY, "cbElements" ) Local $iUBound, $pSafeArrayData, $vt, $data SafeArrayGetUBound( $pSafeArray, 1, $iUBound ) SafeArrayAccessData( $pSafeArray, $pSafeArrayData ) For $i = 0 To $iUBound $vt = DllStructGetData( DllStructCreate( "word", $pSafeArrayData ), 1 ) Switch $vt Case $VT_I4 ; 4 bytes signed integer $data = DllStructGetData( DllStructCreate( "int", $pSafeArrayData + 8 ), 1 ) Case $VT_R8 ; 8 bytes double $data = DllStructGetData( DllStructCreate( "double", $pSafeArrayData + 8 ), 1 ) Case $VT_BSTR ; Basic string $data = SysReadString( DllStructGetData( DllStructCreate( "ptr", $pSafeArrayData + 8 ), 1 ) ) Case Else $data = "" EndSwitch ConsoleWrite( $data & @CRLF ) $pSafeArrayData += $iElemSize Next SafeArrayUnaccessData( $pSafeArray ) EndFunc Func AccVars_SafeArrayToArray( $pvSafeArray, $pArray ) ; <<<< On function entry the native AutoIt array is converted to a safearray contained in a variant >>>> ; --- Get safearray information --- ; $pvSafeArray is a variant that contains a pointer Local $pSafeArray = DllStructGetData( DllStructCreate( "ptr", $pvSafeArray + 8 ), 1 ) ; Array type Local $iVarType SafeArrayGetVartype( $pSafeArray, $iVarType ) Switch $iVarType Case $VT_I2, $VT_I4 ; Signed integers Case $VT_R4, $VT_R8 ; 4/8 bytes floats Case $VT_BSTR ; Basic string Case $VT_BOOL ; Boolean Case $VT_UI4, $VT_UI8 ; 4/8 bytes unsigned integers Case $VT_VARIANT ; Variant Case Else Return SetError(1,0,0) EndSwitch ; --- Set $pArray to match an array --- ; Set vt element to $VT_ARRAY + $iVarType DllStructSetData( DllStructCreate( "word", $pArray ), 1, $VT_ARRAY + $iVarType ) ; Set data element to safearray pointer DllStructSetData( DllStructCreate( "ptr", $pArray + 8 ), 1, $pSafeArray ) ; <<<< On function exit the safearray contained in a variant is converted to a native AutoIt array >>>> EndFunc Client.au3: #AutoIt3Wrapper_Au3Check_Parameters=-d -w- 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #AutoIt3Wrapper_UseX64=Y Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Get default ROT-object (Dictionary object) Local $oDataTransferObject = ObjGet( $CmdLine[1] ) ; Get Dictionary object from ROT-object Local $oDict = $oDataTransferObject.Item( "$oDict" ) Local $oFakeObj = $oDict.Item( "$oFakeObj" ) $oFakeObj.Data("Test string from Client .....") $oFakeObj.Data( 123.123 ) $oFakeObj.Data( 123 ) Local $aArray = [ 123, 123.123, "Client test string" ] $oFakeObj.Data( $aArray ) EndFunc Run Server.au3. Output in SciTE console: Code running on server ... $pVar = 0x000000000045ED30 Type = 0x0008 (VT_BSTR, basic string) pBSTR = 0x0000000000928EE8 (BSTR pointer) data = Test string from Server ..... $pVar = 0x000000000045ED30 Type = 0x0005 (VT_R8, 8 bytes double) data = 123.123 $pVar = 0x000000000045ED30 Type = 0x0003 (VT_I4, 4 bytes signed integer) data = 123 $pVar = 0x000000000045ED30 Type = 0x200C (VT_ARRAY+VT_VARIANT, array of variants, safearray) data = 0x000000000095C7B0 (pointer to safearray) Safearray data: 123 123.123 Server test string Convert safearray to AutoIt array _ArrayDisplay( <AutoIt array> ) ... Code running on Client ... $pVar = 0x000000000045E520 Type = 0x0008 (VT_BSTR, basic string) pBSTR = 0x0000000000926908 (BSTR pointer) data = Test string from Client ..... $pVar = 0x000000000045E520 Type = 0x0005 (VT_R8, 8 bytes double) data = 123.123 $pVar = 0x000000000045E520 Type = 0x0003 (VT_I4, 4 bytes signed integer) data = 123 $pVar = 0x000000000045E520 Type = 0x200C (VT_ARRAY+VT_VARIANT, array of variants, safearray) data = 0x000000000095E8F0 (pointer to safearray) Safearray data: 123 123.123 Client test string Convert safearray to AutoIt array _ArrayDisplay( <AutoIt array> ) ... All code in the 7z-file. FakeObj2.7z1 point
-
Not really as there is also a #pragma option for this these days: #pragma compile(ExecLevel, requireAdministrator) The difference is when defined in the Manifest, it will be handed by the Windows OS were #RequireAdmin is handled by AutoIt3 and the script is re-shelled when not at the required level. Jos1 point
-
MsgBox Yes/No
SkysLastChance reacted to JLogan3o13 for a topic
Or... $firstQuestion = MsgBox(4, "", "My Test Question") $answer = MsgBox(0, "", ($firstQuestion = 6) ? "You clicked Yes" : "You clicked No")1 point -
check if control is disabled
Leendert-Jan reacted to KaFu for a topic
For your own controls. BitAND(GUICtrlGetState($iCtrlId),$GUI_DISABLE) For controls in other windows ControlCommand($hWnd,"","","IsEnabled", "")1 point -
Keyloggers
Leendert-Jan reacted to Melba23 for a topic
Previously when code which was (or could very easily be converted to) a keylogger has appeared on the forum I have limited my actions to deleting the code and warning the poster. I even went to the trouble to post the above announcement so there could be no doubt as to the fact that such code was not permitted here. Yesterday I had to remove code which checked the entire keyboard and lit up the pressed key on a "virtual keyboard" GUI. Note that the post above talks of "code which checks for the best part of the keyboard" - that is exactly what this code did and with the addition of a few lines it could easily have been turned into a crude, but entirely workable, keylogger. The poster is now enjoying a short holiday - and the same fate awaits anyone else who posts similar code in future. The prohibitions in the Forum rules are there to keep this forum clean and to protect the reputation of AutoIt - which is in the interests of us all. Please use your brains and do not post code which flouts the spirit, if not the exact letter, of the rules. If you do then do not complain if you are moderated and warned. M231 point