' ----------------------------------------------------------------------
' Script to list all Scheduled tasks and their available properties
' Written for TaskSchedule 2.0
' ----------------------------------------------------------------------
' <<** Set Log File name and path here **>>
CONST LOGFILE = "C:\TaskListing.txt"
'http://msdn.microsoft.com/en-us/library/windows/desktop/aa382079%28v=vs.85%29.aspx
' Option Explicit
Dim objFSO, objTextFile
Dim objTaskService, objTaskFolder, colTasks
Dim objTask, strstrTaskState
Dim objTaskDefinition, colActions, objTaskAction, arrAttachments, strAttachment
Dim colHeaderFields, objHeaderPair
Dim objPrincipal, objRegistrationInfo, objTaskSettings, objIdleSettings, objTaskNetworkSettings
Dim colTaskTriggers, objTaskTrigger, objTaskRepitition
' Write Task Data to a File
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.CreateTextFile(LOGFILE)
' Create the TaskobjTaskService object and connect
Set objTaskService = CreateObject("Schedule.Service")
call objTaskService.Connect()
' Get the task folder that contains the tasks.
Set objTaskFolder = objTaskService.GetFolder("\")
' Get all of the tasks (Enumeration of 0 Shows all including Hidden. 1 will not show hidden)
Set colTasks = objTaskFolder.GetTasks(0)
If colTasks.Count = 0 Then
objTextFile.WriteLine "No tasks are registered."
Else
For Each objTask In colTasks
' http://msdn.microsoft.com/en-us/library/windows/desktop/aa382079%28v=vs.85%29.aspx
With objTask
objTextFile.WriteLine "Task Name: " & .Name
objTextFile.WriteLine " -Enabled:" & .Enabled
objTextFile.WriteLine " -LastRunTime:" & .LastRunTime
objTextFile.WriteLine " -LastTaskResult:" & .LastTaskResult
objTextFile.WriteLine " -NextRunTime:" & .NextRunTime
objTextFile.WriteLine " -NumberOfMissedRuns:" & .NumberOfMissedRuns
objTextFile.WriteLine " -Path:" & .Path
Select Case .State
Case "0"
strTaskState = "Unknown"
Case "1"
strTaskState = "Disabled"
Case "2"
strTaskState = "Queued"
Case "3"
strTaskState = "Ready"
Case "4"
strTaskState = "Running"
End Select
objTextFile.WriteLine " -Task State: " & .State & "=" & strTaskState
' http://msdn.microsoft.com/en-us/library/windows/desktop/aa382542%28v=vs.85%29.aspx
Set objTaskDefinition = .Definition
With objTaskDefinition
objTextFile.WriteLine " -TASK DEFINITION"
objTextFile.WriteLine " -Data:" & .Data
'http://msdn.microsoft.com/en-us/library/windows/desktop/aa446803%28v=vs.85%29.aspx
Set colActions = objTaskDefinition.Actions
For each objTaskAction in colActions
With objTaskAction
objTextFile.WriteLine " -ACTIONS"
objTextFile.WriteLine " -ID:" & .Id
Select Case .Type
Case 0
objTextFile.WriteLine " -Type:" & .Type & "= Execute / Command Line Operation"
objTextFile.WriteLine " -Arguments :" & .Arguments
objTextFile.WriteLine " -Path:" & .Path
objTextFile.WriteLine " -WorkingDirectory:" & .WorkingDirectory
Case 5
objTextFile.WriteLine " -Type:" & .Type & "= Handler"
objTextFile.WriteLine " -ClassId:" & .ClassId
objTextFile.WriteLine " -Data:" & .Data
Case 6
objTextFile.WriteLine " -Type:" & .Type & "= Email Message"
objTextFile.WriteLine " -From:" & .From
objTextFile.WriteLine " -ReplyTo:" & .ReplyTo
objTextFile.WriteLine " -To:" & .To
objTextFile.WriteLine " -Cc:" & .Cc
objTextFile.WriteLine " -Bcc:" & .Bcc
objTextFile.WriteLine " -Subject:" & .Subject
objTextFile.WriteLine " -Body:" & .Body
objTextFile.WriteLine " -Server:" & .Server
arrAttachments = .Attachments
For each strAttachment in arrAttachments
objTextFile.WriteLine " -Attachment:" & strAttachment
Next 'strAttachment
Set colHeaderFields = .HeaderFields
For each objHeaderPair in ColHeaderFields
objTextFile.WriteLine " -HeaderName:" & objHeaderPair.Name & " | Value:" & objHeaderPair.Value
Next 'objHeaderPair
Case 7
objTextFile.WriteLine " -Type:" & .Type & "=Message Box"
objTextFile.WriteLine " -Title:" & .Title
objTextFile.WriteLine " -MessageBody:" & .MessageBody
End Select
End With 'objTaskAction
Next ' objTaskAction
' http://msdn.microsoft.com/en-us/library/windows/desktop/aa382071%28v=vs.85%29.aspx
Set objPrincipal = .Principal
objTextFile.WriteLine " -PRINCIPAL"
With objPrincipal
objTextFile.WriteLine " -ID:" & .Id
objTextFile.WriteLine " -DisplayName:" & .DisplayName
objTextFile.WriteLine " -GroupId:" & .GroupId
objTextFile.WriteLine " -ID:" & .Id
Select Case .LogonType
Case 0
objTextFile.WriteLine " -LogonType:" & .LogonType & " = None"
Case 1
objTextFile.WriteLine " -LogonType:" & .LogonType & " = Password"
Case 2
objTextFile.WriteLine " -LogonType:" & .LogonType & " = Service 4 Users"
Case 3
objTextFile.WriteLine " -LogonType:" & .LogonType & " = Interactive (User Must be logged in)"
Case 4
objTextFile.WriteLine " -LogonType:" & .LogonType & " = Group"
Case 5
objTextFile.WriteLine " -LogonType:" & .LogonType & " = Local Service/System or Network Service"
Case 6
objTextFile.WriteLine " -LogonType:" & .LogonType & " = Interactive Token then Try Password"
End Select
Select Case .RunLevel
Case 0
objTextFile.WriteLine " -RunLevel:" & .RunLevel & " = Least Privileges (LUA)"
Case 1
objTextFile.WriteLine " -RunLevel:" & .RunLevel & " = Highest Privileges"
End Select
objTextFile.WriteLine " -UserId:" & .UserId
End With 'objPrincipal
'http://msdn.microsoft.com/en-us/library/windows/desktop/aa382100%28v=vs.85%29.aspx
Set objRegistrationInfo = .RegistrationInfo
objTextFile.WriteLine " -REGISTRATION INFO"
With objRegistrationInfo
objTextFile.WriteLine " -Author:" & .Author
objTextFile.WriteLine " -Date:" & .Date
objTextFile.WriteLine " -Description:" & .Description
objTextFile.WriteLine " -Date:" & .Date
objTextFile.WriteLine " -Documentation :" & .Documentation
objTextFile.WriteLine " -SecurityDescriptor:" & .SecurityDescriptor
objTextFile.WriteLine " -Source:" & .Source
objTextFile.WriteLine " -URI:" & .URI
objTextFile.WriteLine " -Version:" & .Version
End With 'objRegistrationInfo
'http://msdn.microsoft.com/en-us/library/windows/desktop/aa383480%28v=vs.85%29.aspx
Set objTaskSettings = .Settings
objTextFile.WriteLine " -TASK SETTINGS"
With objTaskSettings
objTextFile.WriteLine " -AllowDemandStart:" & .AllowDemandStart
objTextFile.WriteLine " -AllowHardTerminate:" & .AllowHardTerminate
Select Case .Compatibility
Case 0
objTextFile.WriteLine " -Compatibility:" & .Compatibility & " = compatible with the AT command"
Case 1
objTextFile.WriteLine " -Compatibility:" & .Compatibility & " = compatible with Task Scheduler 1.0"
Case 2
objTextFile.WriteLine " -Compatibility:" & .Compatibility & " = compatible with Task Scheduler 2.0 (Windows Vista / Windows 2008"
Case 3 ' Not Documented
objTextFile.WriteLine " -Compatibility:" & .Compatibility & " = compatible with Task Scheduler 2.0 (Windows 7 / Windows 2008 R2"
End Select
objTextFile.WriteLine " -DeleteExpiredTaskAfter:" & .DeleteExpiredTaskAfter
objTextFile.WriteLine " -DisallowStartIfOnBatteries:" & .DisallowStartIfOnBatteries
objTextFile.WriteLine " -Enabled:" & .Enabled
objTextFile.WriteLine " -ExecutionTimeLimit:" & .ExecutionTimeLimit
objTextFile.WriteLine " -Hidden:" & .Hidden
Select Case .MultipleInstances
Case 0
objTextFile.WriteLine " -MultipleInstances:" & .MultipleInstances & " = Run in Parallel"
Case 1
objTextFile.WriteLine " -MultipleInstances:" & .MultipleInstances & " = Add to Queue"
Case 2
objTextFile.WriteLine " -MultipleInstances:" & .MultipleInstances & " = Ignore New"
End Select
objTextFile.WriteLine " -Priority:" & .Priority & " (0=High / 10= Low)"
objTextFile.WriteLine " -RestartCount:" & .RestartCount
objTextFile.WriteLine " -RestartInterval:" & .RestartInterval
objTextFile.WriteLine " -RunOnlyIfIdle:" & .RunOnlyIfIdle
objTextFile.WriteLine " -RunOnlyIfNetworkAvailable:" & .RunOnlyIfNetworkAvailable
objTextFile.WriteLine " -StartWhenAvailable:" & .StartWhenAvailable
objTextFile.WriteLine " -StopIfGoingOnBatteries:" & .StopIfGoingOnBatteries
objTextFile.WriteLine " -WakeToRun:" & .WakeToRun
'http://msdn.microsoft.com/en-us/library/windows/desktop/aa380669%28v=vs.85%29.aspx
Set objIdleSettings = .IdleSettings
objTextFile.WriteLine " -IDLE SETTINGS"
With objIdleSettings
objTextFile.WriteLine " -IdleDuration:" & .IdleDuration
objTextFile.WriteLine " -RestartOnIdle:" & .RestartOnIdle
objTextFile.WriteLine " -StopOnIdleEnd:" & .StopOnIdleEnd
objTextFile.WriteLine " -WaitTimeout:" & .WaitTimeout
End With 'objIdleSettings
'http://msdn.microsoft.com/en-us/library/windows/desktop/aa382067%28v=vs.85%29.aspx
Set objTaskNetworkSettings = .NetworkSettings
objTextFile.WriteLine " -NETWORK SETTINGS"
With objTaskNetworkSettings
objTextFile.WriteLine " -ID:" & .Id
objTextFile.WriteLine " -Name:" & .Name
End With 'objTaskNetworkSettings
End With 'objTaskSettings
'http://msdn.microsoft.com/en-us/library/windows/desktop/aa383868%28v=vs.85%29.aspx
Set colTaskTriggers = .Triggers
For Each objTaskTrigger in colTaskTriggers
objTextFile.WriteLine " -TRIGGER"
With objTaskTrigger
objTextFile.WriteLine " -Enabled:" & .Enabled
objTextFile.WriteLine " -Id:" & .Id
objTextFile.WriteLine " -StartBoundary:" & .StartBoundary
objTextFile.WriteLine " -EndBoundary:" & .EndBoundary
objTextFile.WriteLine " -ExecutionTimeLimit:" & .ExecutionTimeLimit
Select Case .Type
Case 0
objTextFile.WriteLine " -Type:" & .Type & " = Event"
objTextFile.WriteLine " -Delay:" & .Delay
objTextFile.WriteLine " -Subscription :" & .Subscription
Case 1
objTextFile.WriteLine " -Type:" & .Type & " = Time"
Case 2
objTextFile.WriteLine " -Type:" & .Type & " = Daily"
objTextFile.WriteLine " -DaysInterval:" & .DaysInterval
Case 3
objTextFile.WriteLine " -Type:" & .Type & " = Weekly"
objTextFile.WriteLine " -WeeksInterval:" & .WeeksInterval
objTextFile.WriteLine " -DaysOfWeek:" & .DaysOfWeek & "=" & ConvertDaysOfWeek(.DaysOfWeek)
Case 4
objTextFile.WriteLine " -Type:" & .Type & " = Monthly"
objTextFile.WriteLine " -DaysOfMonth:" & .DaysOfMonth & "=" & ConvertDaysOfMonth(.DaysOfMonth)
objTextFile.WriteLine " -MonthsOfYear:" & .MonthsOfYear & "=" & ConvertMonthsofYear(.MonthsOfYear)
objTextFile.WriteLine " -RandomDelay:" & .RandomDelay
objTextFile.WriteLine " -RunOnLastDayOfMonth :" & .RunOnLastDayOfMonth
Case 5
objTextFile.WriteLine " -Type:" & .Type & " = Monthly on Specific Day"
objTextFile.WriteLine " -DaysOfWeek:" & .DaysOfWeek & "=" & ConvertDaysOfWeek(.DaysOfWeek)
objTextFile.WriteLine " -MonthsOfYear:" & .MonthsOfYear & "=" & ConvertMonthsofYear(.MonthsOfYear)
objTextFile.WriteLine " -RandomDelay:" & .RandomDelay
objTextFile.WriteLine " -RunOnLastWeekOfMonth :" & .RunOnLastWeekOfMonth
objTextFile.WriteLine " -WeeksOfMonth:" & .WeeksOfMonth & "=" & ConvertWeeksOfMonth(.WeeksOfMonth)
Case 6
objTextFile.WriteLine " -Type:" & .Type & " = When Computer is idle"
Case 7
objTextFile.WriteLine " -Type:" & .Type & " = When Task is registered"
objTextFile.WriteLine " -Delay:" & .Delay
Case 8
objTextFile.WriteLine " -Type:" & .Type & " = Boot"
objTextFile.WriteLine " -Delay:" & .Delay
Case 9
objTextFile.WriteLine " -Type:" & .Type & " = Logon"
objTextFile.WriteLine " -Delay:" & .Delay
objTextFile.WriteLine " -UserId:" & .UserId
Case 11
objTextFile.WriteLine " -Type:" & .Type & " = Session State Change"
Select Case .StateChange
Case 0
objTextFile.WriteLine " -LogonType:" & .StateChange & " = None"
Case 1
objTextFile.WriteLine " -LogonType:" & .StateChange & " = User Session Connect to Local Computer"
Case 2
objTextFile.WriteLine " -LogonType:" & .StateChange & " = User Session Disconnect from Local Computer"
Case 3
objTextFile.WriteLine " -LogonType:" & .StateChange & " = User Session Connect to Remote Computer"
Case 4
objTextFile.WriteLine " -LogonType:" & .StateChange & " = User Session Disconnect from Remote Computer"
Case 7
objTextFile.WriteLine " -LogonType:" & .StateChange & " = On Workstation Lock"
Case 8
objTextFile.WriteLine " -LogonType:" & .StateChange & " = On Workstation Unlock"
End Select
objTextFile.WriteLine " -Delay:" & .Delay
objTextFile.WriteLine " -UserId:" & .UserId
End Select
Set objTaskRepitition = .Repetition
objTextFile.WriteLine " -REPITITION"
With objTaskRepitition
objTextFile.WriteLine " -Duration:" & .Duration
objTextFile.WriteLine " -Interval:" & .Interval
objTextFile.WriteLine " -StopAtDurationEnd:" & .StopAtDurationEnd
End With 'objTaskRepitition
End With 'objTaskTrigger
Next 'objTaskTrigger
End With 'objTaskDefinition
objTextFile.WriteLine
objTextFile.WriteLine " -XML:" & .XML
objTextFile.WriteLine "****************************************"
objTextFile.WriteLine
End With 'objTask
Next
End If
objTextFile.Close
msgbox "Done"
Function ConvertDaysOfMonth(BitValue)
Dim strMsg
If BitValue AND &H01& Then strMsg = "1"
If BitValue AND &H02& Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "2"
End If
If BitValue AND &H04& Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "3"
End if
If BitValue AND &H08& Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "4"
End if
If BitValue AND &H10& Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "5"
End if
If BitValue AND &H20& Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "6"
End if
If BitValue AND &H40& Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "7"
End if
If BitValue AND &H80& Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "8"
End if
If BitValue AND &H100& Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "9"
End if
If BitValue AND &H200& Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "10"
End if
If BitValue AND &H400& Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "11"
End if
If BitValue AND &H800& Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "12"
End if
If BitValue AND &H1000& Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "13"
End if
If BitValue AND &H2000& Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "14"
End if
If BitValue AND &H4000& Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "15"
End if
If BitValue AND &H8000& Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "16"
End if
If BitValue AND &H10000& Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "17"
End if
If BitValue AND &H20000& Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "18"
End if
If BitValue AND &H40000& Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "19"
End if
If BitValue AND &H80000& Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "20"
End if
If BitValue AND &H100000& Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "21"
End if
If BitValue AND &H200000& Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "22"
End if
If BitValue AND &H400000& Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "23"
End if
If BitValue AND &H800000& Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "24"
End if
If BitValue AND &H1000000& Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "25"
End if
If BitValue AND &H2000000& Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "26"
End if
If BitValue AND &H4000000& Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "27"
End if
If BitValue AND &H8000000& Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "28"
End if
If BitValue AND &H10000000& Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "29"
End if
If BitValue AND &H20000000& Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "30"
End if
If BitValue AND &H40000000& Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "31"
End if
If BitValue AND &H80000000& Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "LAST"
End if
ConvertDaysOfMonth = strMsg
End Function
Function ConvertDaysOfWeek(BitValue)
Dim strMsg
If BitValue AND 1 Then strMsg = "Sunday"
If BitValue AND 2 Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "Monday"
End If
If BitValue AND 4 Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "Tuesday"
End if
If BitValue AND 8 Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "Wednesday"
End if
If BitValue AND 16 Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "Thursday"
End if
If BitValue AND 32 Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "Friday"
End if
If BitValue AND 64 Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "Saturday"
End if
ConvertDaysOfWeek = strMsg
End Function
Function ConvertMonthsofYear(BitValue)
Dim strMsg
If BitValue AND 1 Then strMsg = "January"
If BitValue AND 2 Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "February"
End If
If BitValue AND 4 Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "March"
End if
If BitValue AND 8 Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "April"
End if
If BitValue AND 16 Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "May"
End if
If BitValue AND 32 Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "June"
End if
If BitValue AND 64 Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "July"
End if
If BitValue AND 128 Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "August"
End if
If BitValue AND 256 Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "September"
End if
If BitValue AND 512 Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "October"
End if
If BitValue AND 1024 Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "November"
End if
If BitValue AND 2048 Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "December"
End if
ConvertMonthsofYear = strMsg
End Function
Function ConvertWeeksOfMonth(BitValue)
Dim strMsg
If BitValue AND 1 Then strMsg = "First"
If BitValue AND 2 Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "Second"
End If
If BitValue AND 4 Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "Third"
End if
If BitValue AND 8 Then
If len(strMsg) > 0 Then strMsg = strMsg & ", "
strMsg = strMsg & "Fourth"
End if
ConvertWeeksOfMonth = strMsg
End Function
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (2)
Commented:
Windows 7 SP 1, 32 bit. I'm an administrator on the computer, administrator for computers in my OU (not full domain/forest administrator).
Experts Exchange owes you one because you're the only reason I've decided to get a paid account.
Author
Commented:I am glad you found the article helpful and thanks for the kind words.
Concerning your question, you would be best suited to handle this as a question in the VBscript forum. That is monitored by some really smart people, who can also jump in to help out if the article author is not available. I don't have an easy answer to your questions at hand. It may take some back and forth work that will best be done as forum question. I have some questions about what you see and want to keep a lengthy discussion out of the article comments. if you do open a question, you could post a link here and I can go check it out.