Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 09/10/2018 in all areas

  1. We have a lot of sources where you can get information from: Every function of the Excel UDF comes with at least one example A lot of functions that the Excel UDF does not cover are explained in the wiki - including code snippets to include in your script. As the Excel UDF is just a wrapper for Microsofts Excel COM you need some understanding how this works to use the code snippets. For everything else you need to get your feet wet with the MS documentation of the Excel object model (example for Excel 2013) If there is some urgent need for functions which the UDF and the wiki do not cover at the moment I might add them to the wiki. Please post now
    3 points
  2. As the WebDriver UDF - Help & Support thread has grown too big, I started a new one. The prior thread can be found here.
    1 point
  3. BrewManNH

    Remote Service

    psexec already exists.
    1 point
  4. BrewManNH

    About @error

    If there's no array, there's no UBound.
    1 point
  5. water

    About @error

    Another solution we use here! Global $sLogFile = "path and filename of your logfile goes here" ; Catch the MsgBox in case of an error If @Compiled Then _AddHookApi("user32.dll", "MessageBoxW", "_Intercept_MessageBoxW", "int", "hwnd;wstr;wstr;uint") ; Your script goes here ; =============================================================================================================================== ; AutoIt displays a MsgBox for runtime errors. This MsgBox will be replaced with some text written to the error log. ; See: http://www.autoitscript.com/forum/topic/143250-grab-runtime-errors-when-script-is-run-from-a-service/ ; =============================================================================================================================== Func _Intercept_MessageBoxW($hWnd, $sText, $sTitle, $iType) If $sTitle = "AutoIt Error" Then FileWriteLine($sLogFile, $sText) Else Local $aCall = DllCall("user32.dll", "int", "MessageBoxW", _ "hwnd", $hWnd, _ "wstr", $sText, _ "wstr", $sTitle, _ "uint", $iType) If @error Or Not $aCall[0] Then Return 0 Return $aCall[0] EndIf EndFunc ;==>_Intercept_MessageBoxW Func _AddHookApi($sModuleName, $vFunctionName, $vNewFunction, $sRet = "", $sParams = "") Local Static $pImportDirectory, $hInstance If Not $pImportDirectory Then $hInstance = _GetModuleHandle() If @error Then Return SetError(1, 0, 0) Local $aCall = DllCall("dbghelp.dll", "ptr", "ImageDirectoryEntryToData", _ "handle", $hInstance, _ "boolean", 1, _ ; as an image "word", 1, _ ; IMAGE_DIRECTORY_ENTRY_IMPORT "dword*", 0) If @error Or Not $aCall[0] Then Return SetError(2, 0, 0) $pImportDirectory = $aCall[0] EndIf Local $iIsInt = IsInt($vFunctionName) Local $iRestore = Not IsString($vNewFunction) Local $tIMAGE_IMPORT_MODULE_DIRECTORY Local $pDirectoryOffset = $pImportDirectory Local $tModuleName Local $iInitialOffset, $iInitialOffset2 Local $iOffset2 Local $tBufferOffset2, $iBufferOffset2 Local $tBuffer, $tFunctionOffset, $pOld, $fMatch Local Const $PAGE_READWRITE = 0x04 While 1 $tIMAGE_IMPORT_MODULE_DIRECTORY = DllStructCreate("dword RVAOriginalFirstThunk;" & _ "dword TimeDateStamp;" & _ "dword ForwarderChain;" & _ "dword RVAModuleName;" & _ "dword RVAFirstThunk", _ $pDirectoryOffset) If Not DllStructGetData($tIMAGE_IMPORT_MODULE_DIRECTORY, "RVAFirstThunk") Then ExitLoop $tModuleName = DllStructCreate("char Name[64]", $hInstance + DllStructGetData($tIMAGE_IMPORT_MODULE_DIRECTORY, "RVAModuleName")) If DllStructGetData($tModuleName, "Name") = $sModuleName Then ; function from this module $iInitialOffset = $hInstance + DllStructGetData($tIMAGE_IMPORT_MODULE_DIRECTORY, "RVAFirstThunk") $iInitialOffset2 = $hInstance + DllStructGetData($tIMAGE_IMPORT_MODULE_DIRECTORY, "RVAOriginalFirstThunk") If $iInitialOffset2 = $hInstance Then $iInitialOffset2 = $iInitialOffset $iOffset2 = 0 While 1 $tBufferOffset2 = DllStructCreate("dword_ptr", $iInitialOffset2 + $iOffset2) $iBufferOffset2 = DllStructGetData($tBufferOffset2, 1) If Not $iBufferOffset2 Then ExitLoop If $iIsInt Then If BitAND($iBufferOffset2, 0xFFFFFF) = $vFunctionName Then $fMatch = True; wanted function Else $tBuffer = DllStructCreate("ushort Ordinal; char Name[64]", $hInstance + $iBufferOffset2) If DllStructGetData($tBuffer, "Name") == $vFunctionName Then $fMatch = True; wanted function EndIf If $fMatch Then $tFunctionOffset = DllStructCreate("ptr", $iInitialOffset + $iOffset2) _VirtualProtect(DllStructGetPtr($tFunctionOffset), DllStructGetSize($tFunctionOffset), $PAGE_READWRITE) If @error Then Return SetError(3, 0, 0) $pOld = DllStructGetData($tFunctionOffset, 1) If $iRestore Then DllStructSetData($tFunctionOffset, 1, $vNewFunction) Else DllStructSetData($tFunctionOffset, 1, DllCallbackGetPtr(DllCallbackRegister($vNewFunction, $sRet, $sParams))) EndIf Return $pOld EndIf $iOffset2 += DllStructGetSize($tBufferOffset2) WEnd ExitLoop EndIf $pDirectoryOffset += 20 ; size of $tIMAGE_IMPORT_MODULE_DIRECTORY WEnd Return SetError(4, 0, 0) EndFunc ;==>_AddHookApi Func _VirtualProtect($pAddress, $iSize, $iProtection) Local $aCall = DllCall("kernel32.dll", "bool", "VirtualProtect", "ptr", $pAddress, "dword_ptr", $iSize, "dword", $iProtection, "dword*", 0) If @error Or Not $aCall[0] Then Return SetError(1, 0, 0) Return 1 EndFunc ;==>_VirtualProtect Func _GetModuleHandle($vModule = 0) Local $sParamType = "ptr" If IsString($vModule) Then $sParamType = "wstr" Local $aCall = DllCall("kernel32.dll", "ptr", "GetModuleHandleW", $sParamType, $vModule) If @error Or Not $aCall[0] Then Return SetError(1, 0, 0) Return $aCall[0] EndFunc ;==>_GetModuleHandle
    1 point
  6. water

    About @error

    You always have to check for errors. AutoIt does not provide a Catch feature. Runtime errors that pop up an error window are hard to catch. Global $a[1] $a[1] = "*" Exit returns: Array variable has incorrect number of subscripts or subscript dimension range exceeded.: This are coding errors which need to be removed by checking your input data (index etc.) before calling a function.
    1 point
  7. @AlexGo Happy to have helped By the way, I was thinking that you can "short" your code in this way, premising that you have only a webcam $PnPobjWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & "." & "\root\cimv2") $colItemsPnP = $PnPobjWMIService.ExecQuery("SELECT Description from Win32_PnPEntity") For $objItemPnP in $colItemsPnP If $objItemPnP.Description = "USB-Videogerät" Then Exit MsgBox(0,"","Webcam ist verfügbar") Next MsgBox (0,"", "Webcam ist nicht verfügbar")
    1 point
  8. Zedna

    List of files

    #include <GUIConstantsEx.au3> #include <File.au3> Local $aFileList Local $hGui = GUICreate("ProgramData", 450, 300) Local $hButton_txt = GUICtrlCreateCheckbox("File list TXT", 144, 32, 97, 17) Local $hButton_pdf = GUICtrlCreateCheckbox("File list PDF", 144, 62, 97, 17) Local $hList = GUICtrlCreateList("", 10, 100, 430, 200) GUISetState(@SW_SHOW) $aFileList = _FileListToArray(@DesktopDir, "*.*", 1) ; add your path here While True $sMsg = GUIGetMsg() Switch $sMsg Case -3 Exit Case $hButton_txt, $hButton_pdf $want_txt = IsChecked($hButton_txt) $want_pdf = IsChecked($hButton_pdf) GUICtrlSetData($hList, '') If $want_txt Or $want_pdf Then For $i = 1 To UBound($aFileList) - 1 If ($want_txt And StringLower(StringRight($aFileList[$i],4)) == '.txt') Or _ ($want_pdf And StringLower(StringRight($aFileList[$i],4)) == '.pdf') Then GUICtrlSetData($hList, $aFileList[$i]) EndIf Next EndIf EndSwitch WEnd Func IsChecked($control) Return BitAnd(GUICtrlRead($control),$GUI_CHECKED) = $GUI_CHECKED EndFunc
    1 point
  9. LudwigIt, Welcome to the AutoIt forums. A simple way to do what you want is to use a dummy control: #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> $hGUI = GUICreate("Test", 500, 500) $cButton = GUICtrlCreateButton("Button", 10, 10, 80, 30) $cDummy = GUICtrlCreateDummy() GUISetState(@SW_SHOW) ; Set a timestamp $iTimer = TimerInit() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cButton, $cDummy ; Both events fire this code MsgBox($MB_SYSTEMMODAL, "Hi", "Button pressed") EndSwitch ; Check timestamp valid and if delay over 5 secs If $iTimer <> -1 And TimerDiff($iTimer) > 5000 Then ; Fire dummy event GUICtrlSendToDummy($cDummy) ; Invalidate timestamp - try commenting this line and see what happens!!!!!! $iTimer = -1 EndIf WEnd If you want to get a bit more complex you can differentiate between the button and the timer: #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> $hGUI = GUICreate("Test", 500, 500) $cButton = GUICtrlCreateButton("Button", 10, 10, 80, 30) $cDummy = GUICtrlCreateDummy() GUISetState(@SW_SHOW) ; Set a timestamp $iTimer = TimerInit() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cButton, $cDummy ; Both events fire this code ; But message changes depending on the event detected If GUICtrlRead($cDummy) = 9999 Then $sMsg = "Timer fired" ; Clear the dummy data - try commenting this line and see what happens!!!!!! GUICtrlSetData($cDummy, 0) Else $sMsg = "Button pressed" EndIf MsgBox($MB_SYSTEMMODAL, "Hi", $sMsg) EndSwitch ; Check timestamp valid and if delay over 5 secs If $iTimer <> -1 And TimerDiff($iTimer) > 5000 Then ; Fire dummy event GUICtrlSendToDummy($cDummy, 9999) ; Invalidate timestamp - try commenting this line and see what happens!!!!!! $iTimer = -1 EndIf WEnd Please ask if you have any questions. M23 P.S. When you post code in future please use Code tags - see here how to do it. Then you get a scrolling box and syntax colouring as you can see in my posts above. Thanks in advance for your cooperation.
    1 point
  10. Melba23

    Combo Button

    Deye, A "SplitButton" control seems to me like the solution - you code it like this: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <StructureConstants.au3> #include <GuiMenu.au3> $hGUI = GUICreate("Test", 500, 500) $cButton = GUICtrlCreateButton("Main", 10, 10, 80, 30, $BS_SPLITBUTTON) GUISetState() GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cButton MsgBox($MB_SYSTEMMODAL, "Chosen", "Main button") EndSwitch WEnd Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) Local $tStruct = DllStructCreate($tagNMHDR, $lParam) If DllStructGetData($tStruct, "Code") = $BCN_DROPDOWN Then _Dropdown_Menu(DllStructGetData($tStruct, "hWndFrom")) EndIf EndFunc ;==>_WM_NOTIFY Func _Dropdown_Menu($hCtrl) Local Enum $iOption_1 = 1000, $iOption_2 Local $hMenu = _GUICtrlMenu_CreatePopup() _GUICtrlMenu_InsertMenuItem($hMenu, 0, "Option 1", $iOption_1) _GUICtrlMenu_InsertMenuItem($hMenu, 1, "Option 2", $iOption_2) Switch _GUICtrlMenu_TrackPopupMenu($hMenu, $hCtrl, -1, -1, 1, 1, 2) Case $iOption_1 MsgBox($MB_SYSTEMMODAL, "Chosen", "Option 1") Case $iOption_2 MsgBox($MB_SYSTEMMODAL, "Chosen", "Option 2") EndSwitch _GUICtrlMenu_DestroyMenu($hMenu) EndFunc ;==>_Dropdown_Menu M23
    1 point
  11. My signature will do that, but not on the windows 10 version.
    0 points
×
×
  • Create New...