Jump to content

ControlTreeView / Task Scheduler - Help


Go to solution Solved by argumentum,

Recommended Posts

Posted (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.

   image.png.be636ea6f356b5a6973757b589e93fe2.png    image.png.96152c72447a200a15fe38cff1cff232.png   

And using _GUICtrlTreeView_* crashes the Task Scheduler GUI.

Help :baby:

Edited by argumentum

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

  • Solution
Posted (edited)
#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", $iSelectMaxWait = 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
            If Not TaskSchedFolder_SleepOnlySoMuch(250, 5000) 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 $sSelectedLoopCount, $aFolder = StringSplit("#0|#0|" & $sFolder, "|", 0)
    $sFolder = ""
    For $n = 1 To $aFolder[0]
        $hTimer = TimerInit()
        $sSelectedLoopCount = 0 ; reset the anti-infinite-loop
        If $n > 1 Then $sFolder &= "|"
        $sFolder &= $aFolder[$n]
        Do
            $sSelectedLoopCount += 1
            If $sSelectedLoopCount > 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 * $sSelectedLoopCount) ; wait longer if taking longer
            If TimerDiff($hTimer) > $iSelectMaxWait 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 0 ;               keep the sleep going.
    EndIf
    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 by argumentum
better

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Posted

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

 

Posted (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 by argumentum

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Posted

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.

image.thumb.png.a24c8891496367957a9661fae4e2468e.png

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

 

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...