Uploaded image for project: 'Puppet'
  1. Puppet
  2. PUP-4814

Path of scheduled tasks folder is not necessarily C:\Windows\Tasks

    XMLWordPrintable

Details

    • 2
    • Windows 2015-10-21
    • Bug Fix
    • Hide
      Previously puppet's scheduled_task provider on windows assumed the windows system directory was C:\windows\system32, however, it possible for the directory to be on an alternative drive and/or have a different root directory, e.g. D:\winnt\system32. As a result the provider could not manage scheduled tasks. This change uses the SystemRoot environment variable to resolve the correct directory.
      Show
      Previously puppet's scheduled_task provider on windows assumed the windows system directory was C:\windows\system32, however, it possible for the directory to be on an alternative drive and/or have a different root directory, e.g. D:\winnt\system32. As a result the provider could not manage scheduled tasks. This change uses the SystemRoot environment variable to resolve the correct directory.

    Description

      This might be a rare case, but fixing it can improve the code actually.

      If a Windows Server 2003 system is upgraded from Windows 2000 or NT, the default %SYSTEMROOT% or %WINDIR% is C:\WINNT rather than C:\Windows. This will cause failure of scheduled_task resource, because taskscheduler.rb hardcoded the path of scheduled tasks as C:\Windows\Tasks when testing if a job exists.

      Error: /Stage[main]/test/Scheduled_task[foo]: Could not evaluate: No such file or directory @ dir_initialize - C:/Windows/Tasks
      

      I don't think it's a good way:

      • The windows directory doesn't have to be C:\Windows
      • The system drive doesn't have to be C:

      It's better to use "#{ENV['WINDIR']}/Tasks" here.

          # Returns whether or not the scheduled task exists.
          def exists?(job_name)
            bool = false
            Dir.foreach('C:/Windows/Tasks'){ |file|
              if File.basename(file, '.job') == job_name
                bool = true
                break
              end
            }
            bool
          end
      

      Attachments

        1. fr-ss1.PNG
          fr-ss1.PNG
          7 kB
        2. fr-ss2.PNG
          fr-ss2.PNG
          25 kB
        3. fr-ss3.PNG
          fr-ss3.PNG
          51 kB

        Issue Links

          Activity

            People

              ryan.gard Ryan Gard
              digglife Eric Zhu
              Ryan Gard Ryan Gard
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Zendesk Support