argumentum Posted August 26 Posted August 26 (edited) ... Removed the code. The solution has code. ( I was ashamed of the code ) lol ... I want to get this going not just in English but I can't get the info I need for an international version of it. And using _GUICtrlTreeView_* crashes the Task Scheduler GUI. Help Edited August 27 by argumentum Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
Solution argumentum Posted August 26 Author Solution Posted August 26 (edited) expandcollapse popup#RequireAdmin #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=y #AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <WinAPIProc.au3> ConsoleWrite("Did it work: " & (TaskSchedFolder_GotoFolder("\Microsoft\Windows") ? "YES" : "NO") & " - Error: " & @error & @CRLF) Func TaskSchedFolder_GotoFolder($sFolder = "\Microsoft", $iLoadTaskschdMaxWait_mSec = 5000, $iSelectMaxWait_mSec = 3000) If _IsStartedByScheduler() Then Return SetError(4, 0, 0) ; needs to be interactive If Not IsAdmin() Then Return SetError(3, 0, 0) ; needs Admin rights If @StartupDir = "" Or Not FileExists(@StartupDir) Then Return SetError(2, 0, 0) ; can not run as SYSTEM Local $hTimer, $hWin = TaskSchedFolder_WinGetHandle() If Not WinExists($hWin) Then ShellExecute(@WindowsDir & "\system32\taskschd.msc", "/s") TaskSchedFolder_SleepOnlySoMuch() ; init the func Do $hTimer = TimerInit() If Not TaskSchedFolder_SleepOnlySoMuch(250, $iLoadTaskschdMaxWait_mSec) Then ExitLoop $hWin = TaskSchedFolder_WinGetHandle() Until $hWin EndIf If Not WinExists($hWin) Then Return SetError(1, 0, 0) ; GUI not found WinActivate($hWin) $sFolder = StringReplace($sFolder, "\", "|") If StringLeft($sFolder, 1) = "|" Then $sFolder = StringTrimLeft($sFolder, 1) Local $iSelectedLoopCount, $aFolder = StringSplit("#0|#0|" & $sFolder, "|", 0) $sFolder = "" For $n = 1 To $aFolder[0] $hTimer = TimerInit() $iSelectedLoopCount = 0 ; reset the anti-infinite-loop If $n > 1 Then $sFolder &= "|" $sFolder &= $aFolder[$n] Do $iSelectedLoopCount += 1 If $iSelectedLoopCount > 100 Then ExitLoop 2 If $n < $aFolder[0] Then ControlTreeView($hWin, "", "SysTreeView321", "Expand", $sFolder) ControlTreeView($hWin, "", "SysTreeView321", "Select", $sFolder) ; if not Expanded, is just not there. Sleep(50 * $iSelectedLoopCount) ; wait longer if taking longer If TimerDiff($hTimer) > $iSelectMaxWait_mSec Then ExitLoop 2 Until TaskSchedFolder_SameLevel($sFolder, ControlTreeView($hWin, "", "SysTreeView321", "GetSelected", 1)) Next Return Int($n > $aFolder[0]) EndFunc ;==>TaskSchedFolder_GotoFolder Func TaskSchedFolder_SameLevel($sOne, $sTwo) Local $aOne = StringSplit($sOne, "|") Local $aTwo = StringSplit($sTwo, "|") Return Int($aOne[0] = $aTwo[0]) EndFunc ;==>TaskSchedFolder_SameLevel Func TaskSchedFolder_SleepOnlySoMuch($iSleep = Default, $iMaxSleep = 5000) Local Static $hTimer = TimerInit() If $iSleep = Default Then $hTimer = TimerInit() Return EndIf If TimerDiff($hTimer) > $iMaxSleep Then $hTimer = TimerInit() ; just in case the user don't use it as coded, Return SetError(0, 1, 0) ; keep the sleep going. EndIf ; @extended flag shows that it timed out, and not a sleep() failure. If $iSleep > 2147483647 Then $iSleep = 2147483647 ; max 24 days, after that, sleep fails to sleep. If $iSleep < 10 Then $iSleep = 10 ; min 10 mSec, but even at 10, it may be X mSec longer. Return Sleep($iSleep) EndFunc ;==>TaskSchedFolder_SleepOnlySoMuch Func TaskSchedFolder_WinGetHandle() Local $iWinProcess, $sCmdLine, $aWinList = WinList("[CLASS:MMCMainFrame;]") For $n = 1 To UBound($aWinList) - 1 $iWinProcess = WinGetProcess($aWinList[$n][1]) $sCmdLine = _WinAPI_GetProcessCommandLine($iWinProcess) If StringInStr($sCmdLine, "\taskschd.msc") Then Return $aWinList[$n][1] Next EndFunc ;==>TaskSchedFolder_WinGetHandle Func _IsStartedByScheduler() ; https://www.autoitscript.com/forum/topic/184867-check-if-script-is-running-from-taskscheduler/ Local $iPID1 = _WinAPI_GetParentProcess() Local $iPID2 = _WinAPI_GetParentProcess($iPID1) Return StringRegExp(_WinAPI_GetProcessName($iPID1), "taskeng|svchost") And StringRegExp(_WinAPI_GetProcessName($iPID2), "svchost|services") EndFunc ;==>_IsStartedByScheduler Solved Edited August 31 by argumentum better Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
water Posted August 27 Posted August 27 Your solution does not work here. Windows 11, German system language. I just get: Quote 9956 >"C:\WINDOWS\system32\taskschd.msc" /s< 0x00000000000505EC Microsoft Management Console 9956 >"C:\WINDOWS\system32\taskschd.msc" /s< 0x00000000000505EC Microsoft Management Console + WinGetTitle >Microsoft Management Console< - $H1 >< - $H2 >< !!! nope ! Wouldn't it be easier and more reliable to use my Taskscheduler UDF to access the information you are looking for 🤔 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
argumentum Posted August 27 Author Posted August 27 (edited) I want to load the GUI and walk to the folder I make for my stuff. I add a basic entry ( in the code ) and later, add the user/password manually for it to run on its own. I looked at your UDF before reinventing the wheel but did not see a "treeview crawler". 10 minutes ago, water said: Your solution does not work here. Windows 11, German system language. It didn't. I updated it. Try it now Edited August 27 by argumentum Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
water Posted August 27 Posted August 27 Now I get "Did it work: YES - Error: 0" in the SciTe console and the following task scheduler GUI. I did some research and it seems that Task Scheduler does not provide a way to automate the GUI. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
argumentum Posted August 27 Author Posted August 27 Thanks for testing @water. Glad to see that it works on your side too water 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now