Leaderboard
Popular Content
Showing content with the highest reputation on 10/09/2016 in all areas
-
StringRegExpReplace($html, '(?s)<!--.*?-->', "") ; remove comments It's more reliable to compare contents rather than sizes2 points
-
delete me
Mysticdrew reacted to JLogan3o13 for a topic
@Mysticdrew for future reference, we don't often delete conversations. You can ask a Mod to move it for you instead.1 point -
Nice. Just another way for fun. #include <WinAPIProc.au3> If _IsStartedByScheduler() Then MsgBox($MB_ICONINFORMATION, 'ATTENTION', 'This program is run from TASK SCHEDULER "Schedule.service"') Func _IsStartedByScheduler() Local $iPID1 = _WinAPI_GetParentProcess() Local $iPID2 = _WinAPI_GetParentProcess($iPID1) Return _WinAPI_GetProcessName($iPID1) = "svchost.exe" And _WinAPI_GetProcessName($iPID2) = "services.exe" EndFunc ;==>_IsStartedByScheduler Saludos1 point
-
Here is more proper example: #include <MsgBoxConstants.au3> If _TaskScheduler_IsStartedByScheduler() Then MsgBox($MB_ICONINFORMATION, 'ATTENTION', 'This program is run from TASK SCHEDULER "Schedule.service"') Func _TaskScheduler_IsStartedByScheduler() ; Create the Task service object. Local $oShedulerService = ObjCreate("Schedule.service") $oShedulerService.Connect() ; Get the task folder that contains the tasks. Local $oRootFolder = $oShedulerService.GetFolder("\") Local $oTasks_coll = $oRootFolder.GetTasks(0) If $oTasks_coll.Count = 0 Then Return False For $oRegisteredTask_enum In $oTasks_coll If $oRegisteredTask_enum.State = 4 and @AutoItPID = _TaskScheduler_GetRunningTaskPid($oRegisteredTask_enum.Name) Then Return True EndIf Next Return False EndFunc ;==>_TaskScheduler_IsStartedByScheduler Func _TaskScheduler_GetRunningTaskPid($sTaskName) Local $oShedulerService = ObjCreate("Schedule.service") $oShedulerService.Connect() Local $oRunningTasks_coll = $oShedulerService.GetRunningTasks(1) For $oRunningTask_enum In $oRunningTasks_coll If $oRunningTask_enum.Name = $sTaskName Then Return $oRunningTask_enum.EnginePID Next EndFunc ;==>_TaskScheduler_GetRunningTaskPid1 point
-
I have changed the code in post #46 once more. The code is not at all perfect, but getting it working has taken enough time for a single item on the menu. Some of the standard tab controls have a mind of their own (well sort of ). It's a bit crazy anyway. @iamtheky I also did some messing with _DateDayOfWeek(). You can feed the language codes (from the link I posted above) into this function. It seems that only 4 digit codes are supported (on my machine at least). After thinking about your earlier request, It is true that the example in #46 is very specific to my own needs. There are several formats that could be used for input (here it's interpreting the data within a particular control in an unknown locale) and ways in which the return data could be presented. Perhaps you could detail exactly what you want and have a try yourself. I'll get around to it at some point, but this project is consuming much of my time right now. At least you should produce some specs! Return Months and Days in Any Language - _DateDayOfWeek() modified #include <WinAPILocale.au3> #include <Array.au3> Local $aWeek[7] For $i = 0 To 6 $aWeek[$i] = DayOfWeek(1050, $i +1, True) Next _ArrayDisplay($aWeek, "Days of the Week") Local $aMonth[12] For $i = 0 To 11 $aMonth[$i] = MonOfYear(1095, $i +1) Next _ArrayDisplay($aMonth, BinaryToString('0xC2AF5C5F28E38384295F2FC2AF', 4)) Func DayOfWeek($iLangCID, $iDayNum, $bShortName = False) If $bShortName = Default Then $bShortName = False $iDayNum = Int($iDayNum) If $iDayNum < 1 Or $iDayNum > 7 Then Return SetError(1, 0, "") Local $tSYSTEMTIME = DllStructCreate($tagSYSTEMTIME) DllStructSetData($tSYSTEMTIME, "Year", 2006) ; 2006 = Sunday 1st Jan DllStructSetData($tSYSTEMTIME, "Month", 1) DllStructSetData($tSYSTEMTIME, "Day", $iDayNum) Return _WinAPI_GetDateFormat($iLangCID, $tSYSTEMTIME, 0, $bShortName ? "ddd" : "dddd") EndFunc ;==> DayOfWeek Func MonOfYear($iLangCID, $iMonNum, $bShortName = False) If $bShortName = Default Then $bShortName = False $iMonNum = Int($iMonNum) If $iMonNum < 1 Or $iMonNum > 12 Then Return SetError(1, 0, "") Local $tSYSTEMTIME = DllStructCreate($tagSYSTEMTIME) DllStructSetData($tSYSTEMTIME, "Year", 2006) ; 1st month in 2006 = Jan DllStructSetData($tSYSTEMTIME, "Month", $iMonNum) DllStructSetData($tSYSTEMTIME, "Day", 1) Return _WinAPI_GetDateFormat($iLangCID, $tSYSTEMTIME, 0, $bShortName ? "MMM" : "MMMM") EndFunc ;==> MonOfYear After looking into this, I agree with @trancexx, the very first day in history was a Monday (according to Genesis). So you can set the start of time to 2007 if you prefer: read the comments in the original function.1 point
-
CtrlRead not Working
Aadithyaan reacted to l3ill for a topic
Hi, please post your code using the <> in the menu.. Try this: Global $maingui = GUICreate("myCalculator",500,400,-1,-1) Global $bcalc = GUICtrlCreateButton("CALCULATE",360,200,100,30) Global $input1 = GUICtrlCreateInput("",180,50,80,22) ;~ Global $iRead1 = GUICtrlRead($input1) GUICtrlSetOnEvent($bcalc,"myfunction") GUISetOnEvent($GUI_EVENT_CLOSE,"sclose") GUISetState(@SW_SHOW) While 1 Sleep(100) ; Sleep to reduce CPU usage WEnd ;_______________________________________________ func sclose() Exit EndFunc Func myfunction() MsgBox(0,"", GUICtrlRead($input1)) EndFunc1 point -
The example sets the search folder to C:\Windows\System32 and searches for files and folders with "com" in the name. Windows Explorer must be open before you run the example. 8) PerformSearch.au3 #include "Includes\AutomatingWindowsExplorer.au3" #include "Includes\CUIAutomation2.au3" #include <WinAPIShellEx.au3> #include <Array.au3> Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Windows Explorer on XP, Vista, 7, 8 Local $hExplorer = WinGetHandle( "[REGEXPCLASS:^(Cabinet|Explore)WClass$]" ) If Not $hExplorer Then MsgBox( 0, "Automating Windows Explorer", "Could not find Windows Explorer. Terminating." ) Return EndIf ; Get an IShellBrowser interface GetIShellBrowser( $hExplorer ) If Not IsObj( $oIShellBrowser ) Then MsgBox( 0, "Automating Windows Explorer", "Could not get an IShellBrowser interface. Terminating." ) Return EndIf ; --- Set search folder --- ; Get interfaces GetShellInterfaces() ; Set current folder, C:\Windows\System32 Local $pFolder = _WinAPI_ShellILCreateFromPath( "C:\Windows\System32" ) SetCurrentFolder( $pFolder, $SBSP_ABSOLUTE ) ; Free memory _WinAPI_CoTaskMemFree( $pFolder ) ; --- Start a search --- ; Automation object Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation ) If Not IsObj( $oUIAutomation ) Then Return ConsoleWrite( "$oUIAutomation ERR" & @CRLF ) ConsoleWrite( "$oUIAutomation OK" & @CRLF ) ; Explorer object Local $pExplorer, $oExplorer $oUIAutomation.ElementFromHandle( $hExplorer, $pExplorer ) $oExplorer = ObjCreateInterface( $pExplorer, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oExplorer ) Then Return ConsoleWrite( "$oExplorer ERR" & @CRLF ) ConsoleWrite( "$oExplorer OK" & @CRLF ) ; Find condition Local $pCondition ; Use Inspect.exe (Inspect Objects) to verify that the search box is an Edit control $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_EditControlTypeId, $pCondition ) If Not $pCondition Then Return ConsoleWrite( "$pCondition ERR" & @CRLF ) ConsoleWrite( "$pCondition OK" & @CRLF ) ; Find Edit Local $pEdit, $oEdit ; This is the first Edit control $oExplorer.FindFirst( $TreeScope_Descendants, $pCondition, $pEdit ) $oEdit = ObjCreateInterface( $pEdit, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oEdit ) Then Exit ConsoleWrite( "$oEdit ERR" & @CRLF ) ConsoleWrite( "$oEdit OK" & @CRLF ) ; Get Edit Value object Local $pEditValue, $oEditValue $oEdit.GetCurrentPattern( $UIA_ValuePatternId, $pEditValue ) $oEditValue = ObjCreateInterface( $pEditValue, $sIID_IUIAutomationValuePattern, $dtagIUIAutomationValuePattern ) If Not IsObj( $oEditValue ) Then Exit ConsoleWrite( "$oEditValue ERR" & @CRLF ) ConsoleWrite( "$oEditValue OK" & @CRLF ) ; Set search text, com $oEditValue.SetValue( "com" ) ; Wait a second Sleep( 1000 ) ; --- Get search results --- ; Get interfaces (for Search Results right pane window) GetShellInterfaces() ; Wait while the search is performed Local $iCount = 0, $iCountPrev = -1 While $iCount <> $iCountPrev Sleep( 1000 ) ; Wait a second in each loop $iCountPrev = $iCount $iCount = CountItems() WEnd ; Get search results Local $aItems = GetItems( False, True ) ; $fSelected, $fFullPath _ArrayDisplay( $aItems, "Search Results" ) EndFunc The zip contains the example and all include files: Example8.7z I've tested the new example on Windows 10 and 7. It does not work on Windows XP. I've tested the old examples in post 7 on Windows 10. They are all working.1 point
-
..... I had given up on this concept, but coming again on this, I see that I was very close to the goal, I've a way to build a bridge between AutoIt and Javascript. in this way also the many external javascript library could be easly used from AutoIt. here a basic example on how to use native javascript functions from AutoIt: #include <IE.au3> ; *** create a minimal 'html' page listing for the browser Local $sHTML = "<HTML><HEAD><script>" & @CRLF ; html opening tags ; here, within the HEAD tag, we insert the javascript code ; sence the .execscript method is no longer supported (https://msdn.microsoft.com/en-us/library/ms536420(v=vs.85).aspx) ; we have to use the eval method instead. A reference to the global object is needed to access the eval method. See here: ; http://stackoverflow.com/questions/9642491/getting-a-reference-to-the-global-object-in-an-unknown-environment-in-strict-mod ; http://perfectionkills.com/unnecessarily-comprehensive-look-into-a-rather-insignificant-issue-of-global-objects-creation/#ecmascript_5_strict_mode $sHTML &= "var global = (1,eval)('this');" & @CRLF ; the 'global' variable get a handle to the global object $sHTML &= "</script></HEAD></HTML>" & @CRLF ; html closing tags ; *** end of html page listing Local $oIE = _IECreate("about:blank",0,0,0) ; an hidden browser (used as javascript engine provider) _IEDocWriteHTML($oIE, $sHTML) ; inject above html (and library) in browser _IEAction($oIE, "refresh") ; https://msdn.microsoft.com/en-us/library/52f50e9t(v=vs.94).aspx Local $ohJS = $oIE.document.parentwindow.global ; $ohJS is a reference to the Global Obj ; ---- now the javascript engine can be used in our AutoIt script using the $ohJS reference ---- ; example of use: $i = 1000000 ; an unformatted number ; we use a javascript method to format our number ; and we get the result from javascript directly in an AutoIt variable by the javascript eval method ... Local $result = $ohJS.eval('parseInt( ' & $i & ' ).toLocaleString();') MsgBox(0,"Debug", $result) _IEQuit($oIE) Here, another example on how to use an external javascript library called moment.js. it's a library similar to the #include <date.au3> but written in javascript. you have to download the library and save it in the same path of this script before you run it: #include <IE.au3> ; ; to load the moment.js library, get it from the site: http://momentjs.com/ ; and save it to the script path prior to run this script ; Local $sJScript = FileRead(".\moment.js") ; load library from disk ; you could also get it 'on the fly' from the net using InetRead() like this: ; Local $dJScript = InetRead("http://momentjs.com/downloads/moment.js") ; Local $sJScript = BinaryToString($dJScript) ; *** create a minimal 'html' page listing for the browser Local $sHTML = "<HTML><HEAD><script>" & @CRLF ; html opening tags ; ; here, within the HEAD tag, we insert the javascript code ; ; sence the .execscript method is no longer supported (https://msdn.microsoft.com/en-us/library/ms536420(v=vs.85).aspx) ; we have to use the eval method instead. A reference to the global object is needed to access the eval method. ; see here: ; http://stackoverflow.com/questions/9642491/getting-a-reference-to-the-global-object-in-an-unknown-environment-in-strict-mod ; http://perfectionkills.com/unnecessarily-comprehensive-look-into-a-rather-insignificant-issue-of-global-objects-creation/#ecmascript_5_strict_mode $sHTML &= "var global = (1,eval)('this');" & @CRLF ; the 'global' variable get a handle to the global object ; here we include the moment.js library within the HEAD tag (something like #include in AutoIt) $sHTML &= $sJScript & @CRLF $sHTML &= "</script></HEAD></HTML>" & @CRLF ; html closing tags ; *** end of html page listing Local $oIE = _IECreate("about:blank",0,0,0) ; an hidden browser (used as javascript engine provider) _IEDocWriteHTML($oIE, $sHTML) ; inject above html (and library) in browser _IEAction($oIE, "refresh") ; https://msdn.microsoft.com/en-us/library/52f50e9t(v=vs.94).aspx Local $ohJS = $oIE.document.parentwindow.global ; $ohJS is a reference to the Global Obj ; ---- now the javascript engine can be used in our AutoIt script using the $ohJS reference ---- ; example of use: $i = 1000000 ; an unformatted number ; we use a javascript method to format our number ; and we get the result from javascript directly in an AutoIt variable by the javascript eval method ... Local $result = $ohJS.eval('parseInt( ' & $i & ' ).toLocaleString();') MsgBox(0,"Debug", $result) ; here we use a function from the external moment.js library included above... $result = $ohJS.eval("moment().format('LLLL');") MsgBox(0, "Debug", $result) _IEQuit($oIE) I've tested those 2 draft scripts only on ie9 at the moment, but should work even on ie11 since I use the eval method instead of the now unsupported execScript method. those 2 examples are just a proof of concept, and I think that can be improved, but in my opinion this "bridge" is an interesting tool.... improvements and suggestions are welcome. Thank You everybody.1 point
-
a similar "tecnique" already used here (again from the good @czardas )1 point