strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colScheduledJobs = objWMIService.ExecQuery("Select Name from Win32_ScheduledJob")
strNames = ""
For Each objJob in colScheduledJobs
MsgBox objJob.Name
If strNames = "" Then
strNames = objJob.Name
Else
strNames = strNames & ";" & objJob.Name
End If
Next
arrNames = Split(strNames, ";")
For Each strName In arrNames
MsgBox strName
Next
MsgBox "Done"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1
strTempOutputFile = objFSO.GetFolder(Replace(wscript.ScriptFullName, wscript.ScriptName, "")).ShortPath & "TempSchTasksOutput.txt"
Set objShell = CreateObject("WScript.Shell")
objShell.Run "cmd /c schtasks > " & strTempOutputFile, 0, True
Set objTemp = objFSO.OpenTextFile(strTempOutputFile, intForReading, False)
strNames = ""
While Not objTemp.AtEndOfStream
strLine = Trim(objTemp.ReadLine)
If strLine <> "" Then
If Left(strLine, 8) <> "TaskName" And Left(strLine, 8) <> "========" And Left(strLine, 8) <> "Folder: " And Left(strLine, 8) <> "INFO: Th" Then
If strNames = "" Then
strNames = Trim(Left(strLine, 40))
Else
strNames = strNames & ";" & Trim(Left(strLine, 40))
End If
End If
End If
Wend
objTemp.Close
objFSO.DeleteFile strTempOutputFile, True
arrNames = Split(strNames, ";")
For Each strName In arrNames
WScript.Echo strName
Next
WScript.Echo "Done"
Probably the objJob.Name property, or the objJob.Command property contains that "taskname" data you are looking for.
Open in new window