10 Replies Latest reply on Apr 16, 2014 12:56 PM by NeoIsTaken

    Get Windows Scheduled Tasks in Inventory

    Rookie

      Has anyone come up with a solution for getting the Windows Scheduled Tasks in Inventory?  I am pretty sure it could be done with the combination of ldscnhlp.ini, schtasks.exe, and some script to generate a data file in the format LANDesk understands.  Before I tackle this, I thought it would be good to check if anyone has already done it.

        • 1. Re: Get Windows Scheduled Tasks in Inventory
          Employee

          it's been on the ldms_client todo list for a while, nothing yet though... any help would be welcome.

           

          It could probably also be done as a vbscript-driven custom vulnerability. You might look at this as a starting point: http://www.droppedpackets.org/security/custom-definitions/v_intl_runonce.xml/view

          • 2. Re: Get Windows Scheduled Tasks in Inventory
            zman Master

            The information is not stored in the registery and is stored in a .job file.  Depending on what information you want to pull in LANDesk (there is a lot in a job file), here is some autoit code (not mine but it works, maybe that is why it works) that pulls all the scheduled task information into an array. Take the array and simply right it to the registry for LANDeks to pick it up.

             

             #include <Constants.au3> 
              #include <Array.au3> 
              Local $line 
              Local $line2 
              ;                         Add /NH to command to remove headers 
              Local $foo = Run(@ComSpec & ' /c schtasks.exe /query /FO csv /V', @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) 
                  
              While ProcessExists($foo) 
                  $line = StdoutRead($foo, True) 
                  $line2 = StderrRead($foo, True) 
              WEnd 
             
              For $i = 1 To 3 
                  If StringLeft($line,  1)  = @CR OR StringLeft($line,  1)  = @CRLF OR StringLeft($line,  1)  = @LF Then $line  = StringTrimLeft($line,  1) 
                  If StringLeft($line2, 1)  = @CR OR StringLeft($line2, 1)  = @CRLF OR StringLeft($line2, 1)  = @LF Then $line2 = StringTrimLeft($line2, 1) 
                  If StringRight($line, 1)  = @CR OR StringRight($line, 1)  = @CRLF OR StringRight($line, 1)  = @LF Then $line  = StringTrimRight($line, 1) 
                  If StringRight($line2,1)  = @CR OR StringRight($line2,1)  = @CRLF OR StringRight($line2,1)  = @LF Then $line2 = StringTrimRight($line2,1) 
              Next 
             
              $line = _CSVToArray(0, ",", $line) 
             
              _ArrayDisplay($line) 
             
             
             
              ;UDF Needed For CSV Functions 
             
              ;=============================================================================== 
              ; 
              ; Description:      Reads a CSV file into a 2D array 
              ; Parameter(s):     $sType       - Type of data to parse 
              ;                                        0 - String 
              ;                                        1 - CSV File 
              ;                   $cSeparator  - Separator character, default is comma (,) 
              ;                   $sString     - String to be processed       (If $Stype = 0) 
              ;                   $sPath       - Path to the CSV file to read (If $Stype = 1) 
              ; Requirement(s):   None 
              ; Return Value(s):  On Success - 2D CSV array 
              ;                   On Failure - 0  and Set 
              ;                                   @ERROR to:  1 - File not found/openable 
              ;                                               2 - File read error 
              ;                                               3 - CSV format error 
              ; Author(s):        Ed Fletcher 
              ; Note(s):          Pattern based on work by Jeffrey E. F. Friedl in 
              ;                   "Mastering Regular Expressions, 2nd Edition" 
              ;=============================================================================== 
              Func _CSVToArray( $sType, $cSeparator=',', $sString = "", $sPath = "" ) 
             
              If $sType = 1 And $sPath = "" Then 
                  SetError(1) 
                  Return 0 
              ElseIf $sType = 0 And $sString = "" Then 
                  SetError(3) 
                  Return 0 
              EndIf 
             
              ;; open the file and read the entire CSV dataset into one string. 
              If $sType = 1 Then 
              ;; open the file and read the entire CSV dataset into one string. 
             
                  Local $hFile = FileOpen( $sPath, 0 ) 
                  If $hFile == -1 Then 
                      SetError( 1 ) 
                      Return 0 
                  EndIf 
             
                  Local $sRawData = FileRead( $hFile ) 
                  If @error > 0 Then 
                      FileClose( $hFile ) 
                      SetError( 2 ) 
                      Return 0 
                  EndIf 
             
                  FileClose( $hFile ) 
              Else 
                  $sRawData = $sString 
              EndIf 
             
              ;; parse the string into an array of matched fields 
             
                  Local $pattern = '(?m)'                    ; multi-line search mode 
                  $pattern &= '\G(?:^|[' & $cSeparator & '])' ; start of line or start of field 
                  $pattern &= '(?:'                          ; one of two options: 
                  $pattern &= '"'                            ;   a field starting with at double quote 
                  $pattern &= '([^"]*+(?:""[^"]*+)*+)'    ;   (quote-pairs and any non-quote chars) 
                  $pattern &= '"'                            ;   a double quote ending the field 
                  $pattern &= '(\r?\n?)'                     ;   (any sort of line ending here?) 
                  $pattern &= '|'                            ; or: 
                  $pattern &= '([^"' & $cSeparator & '\r\n]*+)';   (a simple CSV field, no quotes or commas) 
                  $pattern &= '(\r?\n?)'                     ;   (any sort of line ending here?) 
                  $pattern &= ')'                            ; note that we should have 4 captures per CSV element 
             
                  Local $aRawData = StringRegExp( $sRawData, $pattern, 4 ) 
                  If @error <> 0 Then 
              ;Die( 'Error: ' & @error ) 
                      SetError( 3 ) 
                      Return 0 
                  EndIf 
             
                  $sRawData = ''; we're done with this, and it might be large 
             
              ; $aRawData is a 1D array containing every field in the CSV file.  Each element 
              ; in $aRawData is an array of 5 strings, like so: 
              ; 0 - all of the characters consumed while matching this field 
              ; 1 - field contents, if the field was double quoted 
              ; 2 - a line ending, if the field was double quoted and this is the end of the line 
              ; 3 - field contents, if the field was *not* double quoted 
              ; 4 - a line ending, if the field was *not* double quoted and this is the end of the line 
             
             
              ;; pass through the results once to determine the number of rows and the max number of columns 
             
                  Local $i, $aMatch 
                  Local $colCount = 0, $maxCols = 0 
                  Local $rowCount = 0 
             
                  For $i=0 To UBound($aRawData)-1 
                      $aMatch = $aRawData[$i] 
             
                      If $colCount == 0 Then 
                          $rowCount += 1    ; we're looking at the first field on the current row 
                      EndIf 
             
                      $colCount += 1 
             
                      If $colCount > $maxCols Then 
                          $maxCols = $colCount; longest row so far... 
                      EndIf 
             
                      If $aMatch[2] <> '' OR (UBound($aMatch) > 3 AND $aMatch[4] <> '') Then 
                          $colCount = 0    ; row complete, we might start a new one 
                      EndIf 
                  Next 
             
              ;; we now know how large to make our 2D output array 
                  
                  Local $aCsvData[$rowCount][$maxCols] 
             
             
              ;; finally, populate our output array 
             
                  Local $row = 0, $col = 0 
             
                  For $i=0 To UBound($aRawData)-1 
                      $aMatch = $aRawData[$i] 
             
                      If UBound($aMatch) > 3 AND $aMatch[3] <> '' Then 
                  ; It was a simple field, no processing required 
                          $aCsvData[$row][$col] = $aMatch[3] 
                      Else 
                  ; It was a quoted value, so take care of embedded double quotes 
                          $aCsvData[$row][$col] = StringReplace($aMatch[1], '""', '"') 
                      EndIf 
             
                      $col += 1 
             
              ; now look for a line ending that ends the current data row 
                      If $aMatch[2] <> '' OR (UBound($aMatch) > 3 AND $aMatch[4] <> '') Then 
                          $row += 1 
                          $col = 0 
                      EndIf 
                  Next 
             
                  Return $aCsvData 
              EndFunc
            
            1 of 1 people found this helpful
            • 3. Re: Get Windows Scheduled Tasks in Inventory
              Apprentice

              A year later and there hasn't been much progess on having Windows Scheduled Tasks available in inventory yet, right?

              • 4. Re: Get Windows Scheduled Tasks in Inventory
                Rookie

                I took the Autoit script Zman posted and customized it for my needs.  It is limited to Windows Server 2003 and Windows XP, because Windows Vista and later use a different CSV format.

                 

                LANDesk desperately needs to give the inventory functionality a major update.  I think it has been neglected for far too many versions.  RAM is still reported in kilobytes (as of version 8.8)...

                • 5. Re: Get Windows Scheduled Tasks in Inventory
                  zman Master

                  So I would start a new thread asking for any new Inventory Enhancments users would like to have in the product. Not too many people are going to see this buried in a year old thread.  Just inventory enhancments nothing more nothing less ;-)

                  • 6. Re: Get Windows Scheduled Tasks in Inventory
                    Specialist

                    6 years later.... Did I miss something?

                     

                     

                     

                    Idea created: http://community.landesk.com/support/ideas/3696 (Link fixed)

                    Please upvote this to get it added

                    • 8. Re: Get Windows Scheduled Tasks in Inventory
                      Specialist

                      Odd, copy and pasted from my browser.

                      Link corrected.

                       

                      http://community.landesk.com/support/search.jspa?dateRange=all&peopleEnabled=true&resultTypes=idea&q=Get+Windows+Scheduled+Tasks+in+Inventory&containerType=14&container=2265&containerName=Management+Suite-ER&username=&rankBy=relevance&newq=Get+Windows+Scheduled+Tasks+in+Inventory*&numResults=15

                       

                      Here is a search link, I should have done this from the start. There appears to be another requests for this.

                       

                      Question for LDMS Support,

                      Is it possible to combine the duplicate "Ideas"

                      • 9. Re: Get Windows Scheduled Tasks in Inventory
                        Rick.Smith1 Specialist

                        David,

                         

                        I am actually going to go through and check my posts as well where I have included links to ERs... it appears to be a bug in my opinion with this community forum. I got it to work by clicking on the hyperlink insert button, then finding the article in Browse History tab... probably could find it too in the middle tab by searching..

                         

                        My link is just your ER. I didnt create a new one, I voted yours up previously and just came across this article and tried clicking on your link to see if it was the same one.

                        • 10. Re: Get Windows Scheduled Tasks in Inventory
                          Specialist

                          no worries, I actually created the duplicate

                           

                          This request was made 2years ago here: Inventory of Windows Task Scheduler

                          (That method works well, thx )