-
Posts
1,368 -
Joined
-
Last visited
-
Days Won
5
Community Answers
-
Ascend4nt's post in ObjEvent dont work was marked as the answer
I don't understand why you are setting FEATURE_BROWSER_EMULATION to 11001 when you have IE 10? And what doesn't work exactly? RegDelete()?
Oh, also I decided why not check the parentNode in the 'onclick' function. It's a better solution, although you'll probably add extra code to prevent EVERY click from checking the parent (say, only looking it up for img and span elements):
#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <IE.au3> Opt("GUIOnEventMode", 1) Opt("GUICloseOnESC",1) Global $MainWindow = GUICreate("Main Window", 833, 822, 335, 214) GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEMain", $MainWindow) $oIE = _IECreateEmbedded () GUICtrlCreateObj($oIE, 10, 10, 500, 400) _IENavigate($oIE, @ScriptDir&"/images/index.html") ;_IEDocWriteHTML($oIE,fileread(@ScriptDir&"/images/index.html")); "<html><body><button id=""BTN"">Press This</button><br><br><button id=""BTk"">Press This</button></body></html>") _IELoadWait($oIE) #cs Local $oDOMElem ; Optionally Loop through the elements with attributes id=1 to id=4, abort all navigation For $i = 1 to 4 $oDOMElem = $oIE.document.getElementById($i) ; Anchor element? If $oDOMElem.nodeType = 1 And $oDOMElem.nodeName = "A" Then ConsoleWrite("node of id '" & $i & "': type = " & $oDOMElem.nodeType & ", name = " & $oDOMElem.nodeName & @LF) $oDOMElem.setAttribute("onclick","return false;") EndIf Next #ce Local $oDocEvents = ObjEvent($oIE.document, "Event_", "HTMLDocumentEvents2") #forceref $oDocEvents ;Local $oAEvents = ObjEvent($oIE.document, "Event_", "HTMLAnchorEvents2") ;#forceref $oAEvents ; _IEErrorHandlerRegister("MyErrFunc") GUISetState(@SW_SHOW, $MainWindow) ; will display an empty dialog box While 1 Sleep(1000) ; Idle around WEnd Exit ;-- Open new window when button in 'IE' pressed volatile Func Event_onclick($oEvtObj) If IsObj($oEvtObj) Then Local $oElem = $oEvtObj.srcElement If Not IsObj($oElem) Then Return Local $nId = $oElem.id ;ConsoleWrite("ID of srcElement = " & $nId & @LF) If $nId = 0 Then $oElem = $oElem.parentNode If Not IsObj($oElem) Or $oElem.id = 0 Or $oElem.nodeName <> 'A' Then ConsoleWrite("Click not associated with any DOM element, and parent is not <a>nchor or has no id attribute" & @LF) Return EndIf $nId = $oElem.id EndIf ; Now we have an ID Switch $nId Case 0 ; prevent 0 = 'anystring' matching Case "1" ConsoleWrite("UPLOAD"&@LF) Case "2" ConsoleWrite("DOWNLOAD"&@LF) Case "3" ConsoleWrite("ABOUT"&@LF) Case "4" Exit Case Else ConsoleWrite("Click of element id '" & $oEvtObj.srcElement.id & "' received" & @LF) EndSwitch ; Optionally Prevent click from going through ;$oEvtObj.returnValue = False EndIf EndFunc Volatile Func Event_oncontextmenu($oEvtObj) If IsObj($oEvtObj) Then $oEvtObj.returnValue = False EndFunc Func CLOSEMain() Exit EndFunc *Edit: Now it looks specifically for <a> anchor parent elements. Also added 'oncontextmenu' function as an example how you can disable right-clicking (the html file has a script function for this, but its not called. Alternatively, modify this line in the html file:
<body oncontextmenu="return false;"> -
Ascend4nt's post in Prevent AutoIt script from being stripped from Exe? was marked as the answer
Why yes, yes there is d4nny boy. Look at >PE File Overlay Extraction. Boom, y'alls answer been resolved! Suck it!
Edit: with v3.3.10.0+, there's a new way to detect AutoIt scripts. Of course, I've done myself another service and answered my question (in a different way) with a new UDF.. see >A3X File Extract
-
Ascend4nt's post in compare mouse cursor position - code efficiency was marked as the answer
To get distance for x and y, just use Abs() in combination with x2-x1 or y2-y1. That will reduce the comparisons by 2
-
Ascend4nt's post in C#\C++ to Autoit was marked as the answer
Just messing around with it, this is what it looks like might be on the right track.. You need pointers to the functions, and the array has to be a DLLStruct.. I was lazy and didnt' declare most variables though. And I can't test it..
Dim $DLL = DllOpen('nvapi.dll') $N = NvAPI_Initialize() ConsoleWrite("Return = " & $N & ", @error = " & @error & ", @extended = " & @extended & @CRLF) $R = NvAPI_EnumPhysicalGPUs() _ArrayDisplay($R) For $i = 0 To 100 NvAPI_GPU_GetUsages($R[0]) Sleep(1000) Next DllClose($DLL) Func NvAPI_QueryInterface($nInterface) $result = DllCall($DLL, "ptr:cdecl", 'nvapi_QueryInterface', 'int', $nInterface) If @error Then Return SetError(2,@error,0) If $result[0] = 0 Then Return SetError(3,0,0) Return $result[0] EndFunc Func NvAPI_Initialize() Static Local $pInitialize = 0 If $pInitialize = 0 Then $pInitialize = NvAPI_QueryInterface(0x0150E828) If $pInitialize = 0 Then Return SetError(@error,@extended,0) EndIf $result = DllCallAddress("int:cdecl", $pInitialize) If @error Then Return SetError(2,@error,False) Return $result[0] EndFunc Func NvAPI_EnumPhysicalGPUs() Static Local $pEnumPhysGPUs = 0 If $pEnumPhysGPUs = 0 Then $pEnumPhysGPUs = NvAPI_QueryInterface(0xE5AC921F) If $pEnumPhysGPUs = 0 Then Return SetError(@error, @extended, 0) EndIf $stGPUHandles = DllStructCreate("ptr gpuHandles[64];") $result = DllCallAddress("int:cdecl", $pEnumPhysGPUs, 'ptr', DllStructGetPtr($stGPUHandles), 'int*', 0) If @error Then Return SetError(2,@error,0) If $result[0] Then Return SetError(3,0,0) $nGPUCount = $result[2] Dim $result[$nGPUCount] For $i = 1 To $nGPUCount $result[$i - 1] = DllStructGetData($stGPUHandles, 1, $i) Next Return $result EndFunc Func NvAPI_GPU_GetUsages($vGPUHandle) Static Local $pGetUsages = 0 If $pGetUsages = 0 Then $pGetUsages = NvAPI_QueryInterface(0x189A1FDF) If $pGetUsages = 0 Then Return SetError(@error, @extended, 0) EndIf $stGPUUsages = DllStructCreate("uint gpuUsages[34];") DLLStructSetData($stGPUUsages, 1, BitOR(34 * 4, 0x10000), 1) $result = DllCallAddress("int:cdecl", $pGetUsages, 'ptr', $vGPUHandle, 'ptr', DllStructGetPtr($stGPUUsages)) If @error Then Return SetError(2,@error,0) If $result[0] Then Return SetError(3, 0, 0) Return DllStructGetData($stGPUUsages, 1, 4) ; 4 is equivalent to c's array[3] EndFunc *edit: Fixed parameters and parameter return check (non-zero is error).. AND indexing. Still not sure its entirely kosher though
-
Ascend4nt's post in How to Know PID in this case was marked as the answer
well, f*k me, I guess I like a good challenge. Here's a UDF for finding processes that started after a given time point:
; ======================================================================================================== ; <_ProcessListAfterTimePoint.au3> ; ; Functions to get an array of processes that started after a given time point ; Example included displays array of processes ; ; Functions: ; _WinTime_GetSystemTimeAsLocalFileTime() ; Gets current time as 64-bit FILETIME (_WinTimeFunctions UDF) ; _ProcessListAfterTime() ; Gets list of processes after a certain timepoint (as FILETIME) ; ; Author: Ascend4nt ; ======================================================================================================== #include <WinAPI.au3> ; ProcessOpen/CloseHandle ; ============================================================================================== ; Func _WinTime_GetSystemTimeAsLocalFileTime() ; ; Function to grab the current system time as 64bit Local FileTime (not UTC) ; (from _WinTimeFunctions UDF) ; ; Return: ; Success: 64-bit value representing the UTC-based FileTime ; Failure: -1, with @error set: ; @error = 2 = DLL Call error, @extended = actual DLLCall error code ; ; Author: Ascend4nt ; ============================================================================================== Func _WinTime_GetSystemTimeAsLocalFileTime() Local $aRet=DllCall("kernel32.dll","none","GetSystemTimeAsFileTime","uint64*",0) If @error Then Return SetError(2,@error,-1) Return $aRet[1] EndFunc ; ============================================================================================== ; Func _ProcessListAfterTime($nSysTime, $vProcFilter = "") ; ; Returns an array of Processes that started after a given time point (as FILETIME) ; ; $nSysTime = a 64-bit FILETIME value (see GetSystemTimeAsFileTime) to use ; as the starting point ; ; $vProcFilter = Process name filter ("calc.exe") or "" for ALL processes ; ; Returns: ; Success: An array of processes in the same form as ProcessList: ; [0][0] = # of processes ; [i][0] = Process name ; [i][1] = Process ID # ; ; Failure: "" with @error set (only happens if ProcessList() itself fails) ; ; ; Author: Ascend4nt ; ============================================================================================== Func _ProcessListAfterTime($nSysTime, $vProcFilter = "") Local $aProcList, $aFoundList, $nFound Local $iAccess, $hProcess If $vProcFilter = "" Then $aProcList = ProcessList() Else $aProcList = ProcessList($vProcFilter) EndIf If @error Then Return SetError(@error,0,"") ; XP, XPe, 2000, or 2003? - Affects process access requirement If StringRegExp(@OSVersion,"_(XP|200(0|3))") Then $iAccess = 0x0400 ; PROCESS_QUERY_INFORMATION Else $iAccess = 0x1000 ; PROCESS_QUERY_LIMITED_INFORMATION EndIf Dim $aFoundList[$aProcList[0][0]+1][2] $nFound = 0 For $i = 1 To $aProcList[0][0] $hProcess = _WinAPI_OpenProcess($iAccess, False, $aProcList[$i][1]) $aRet = DllCall("kernel32.dll", "bool", "GetProcessTimes", "handle", $hProcess, "uint64*", 0, "uint64*", 0, "uint64*", 0, "uint64*", 0) If Not @error And $aRet[0] And $aRet[2] > $nSysTime Then ConsoleWrite("Found process that started after timepoint: " & $aProcList[$i][0]&", PID #" & $aProcList[$i][1] & @CRLF) $nFound += 1 $aFoundList[$nFound][0] = $aProcList[$i][0] $aFoundList[$nFound][1] = $aProcList[$i][1] EndIf _WinAPI_CloseHandle($hProcess) Next $aFoundList[0][0] = $nFound ReDim $aFoundList[$nFound + 1][2] Return $aFoundList EndFunc ; --- EXAMPLE USAGE --- #include <Array.au3> Local $nSysTime, $aProcList $nSysTime = _WinTime_GetSystemTimeAsLocalFileTime() Sleep(10) ; Some systems may need a small sleep (see MichaelIslamet's posts) Run("calc.exe") Run("notepad.exe") Sleep(500) $aProcList = _ProcessListAfterTime($nSysTime) _ArrayDisplay($aProcList, "Processes that started after start point") In michaelslamet's case, call it like _ProcessListAfterTime($nSysTime, "iexplore.exe").
*edit: Added Sleep(10) after getting the System Time. May or may not be system-specific issue (see >MichaelIslamet's post)
-
Ascend4nt's post in CLSID "Shell.Application"(Solved) was marked as the answer
CLSID_Shell is declared as {13709620-C279-11CE-A49E-444553540000} in <Shldisp.h>.
You can use 'StringFromCLSID' or 'StringFromGUID2' to get the number.
-
Ascend4nt's post in C++ error LNK2005: .... already defined was marked as the answer
John,
Because you declared that function outside of the class, for every C++ file that includes the header, duplicate versions of that function will be created - which is correct compiler behavior. That's why you should either declare the function in its own C++ file, declare it as inline, or put it inside the class object definition (which behaves like inline).
-
Ascend4nt's post in StringSplit $CmdLineRaw was marked as the answer
This is the PCRE I use for separating parameters.
There is a look-behind and look-ahead assertion to prevent grabbing quotes, while also allowing for cases where there are empty quotes (""):
Local $aParsedArray=StringRegExp($sStringToParse,'((?<=\s"|^")[^"]+(?=")|[^\s"]+)',3)
The only thing I'd do beforehand is expand any environment strings like %windir%. All you'd need for that is to just set the "ExpandEnvStrings" option, assign the string to itself (looks dumb, but accomplishes the needed expansion), then reset the option.