puppetlabs/puppet · error · Puppet::Util::Windows::Error

Service query for %{parameter_name} failed

Error message

Service query for %{parameter_name} failed

What it means

Raised by Puppet::Util::Windows::Service#query_config2 when QueryServiceConfig2W returns FALSE while reading an optional per-service parameter. The only info level currently mapped is SERVICE_CONFIG_DELAYED_AUTO_START_INFO, and parameter_name is filled from SERVICE_CONFIG_TYPES, so the message names the parameter (e.g. 'SERVICE_CONFIG_DELAYED_AUTO_START_INFO'). Like other Puppet::Util::Windows::Error raises, it embeds the Win32 error from GetLastError.

Source

Thrown at lib/puppet/util/windows/service.rb:523

          # to fail. Just ignore it
          QueryServiceConfig2W(service, info_level, FFI::Pointer::NULL, 0, bytes_pointer)
          size_required = bytes_pointer.read_dword
          FFI::MemoryPointer.new(size_required) do |ssp_ptr|
            # We need to supply the appropriate struct to be created based on
            # the info_level
            case info_level
            when SERVICE_CONFIG_DELAYED_AUTO_START_INFO
              config = SERVICE_DELAYED_AUTO_START_INFO.new(ssp_ptr)
            end
            success = QueryServiceConfig2W(
              service,
              info_level,
              ssp_ptr,
              size_required,
              bytes_pointer
            )
            if success == FFI::WIN32_FALSE
              raise Puppet::Util::Windows::Error, _("Service query for %{parameter_name} failed") % { parameter_name: SERVICE_CONFIG_TYPES[info_level] }
            end

            yield config
          end
        end
      end
      private :query_config2

      # @api private
      # Sets an optional parameter on a service by calling
      # ChangeServiceConfig2W
      #
      # @param [String] service_name name of service
      # @param [Integer] change parameter to change
      # @param [struct] value appropriate struct based on the parameter to change
      def set_optional_parameter(service_name, change, value)
        open_service(service_name, SC_MANAGER_CONNECT, SERVICE_CHANGE_CONFIG) do |service|
          success = ChangeServiceConfig2W(

View on GitHub (pinned to e227c27540)

Solutions

  1. Confirm the service exists and is a win32 user-mode service, not a kernel driver (`sc qc <name>`).
  2. Run Puppet elevated as Administrator so QueryServiceConfig2W is permitted.
  3. Remove the delayed-start configuration for the resource if the OS/service type does not support it.
  4. Re-run the agent to rule out a transient SCM state (service being deleted or reinstalled concurrently).
  5. Check the wrapped Win32 code in the message to pinpoint which of the above applies.

Example fix

# before
Puppet::Util::Windows::Service.new_query_config_2? # internal helper reading delayed auto start

# after - guard before using delayed start
if svc.respond_to?(:delayed_auto_start?) # only meaningful for user-mode win32 services
  Puppet::Util::Windows::Service.set_startup_mode_delayed(service_name, true)
end
Defensive patterns

Strategy: try-catch

Validate before calling

# only apply delayed-start to user-mode win32 services, not drivers
info = `sc qcaption` # or parse `sc qc #{name}`
# TYPE : 10  WIN32_OWN_PROCESS is safe; 1 KERNEL_DRIVER / 2 FILE_SYSTEM_DRIVER are not

Try / catch

begin
  Puppet::Util::Windows::Service.set_startup_mode_delayed(name, true)
rescue Puppet::Util::Windows::Error => e
  raise unless e.code == 5 || e.code == 1247 # ERROR_ACCESS_DENIED, ERROR_INVALID_LEVEL
  Puppet.warning("delayed-start not supported/denied for #{name}; skipping")
end

Prevention

When it happens

Trigger: Reading or applying the 'delayed start' setting on a service (startup_config / set_startup_mode_delayed paths) when QueryServiceConfig2W fails: ERROR_ACCESS_DENIED on a locked-down service, ERROR_INVALID_HANDLE after the service was deleted, ERROR_INVALID_LEVEL on an OS/instance that does not support the delayed-auto-start level (e.g. kernel drivers or older Windows).

Common situations: Setting `enable => true, hasstatus => ...` manifests combined with delayed start on machines where the service binary is a kernel driver; a service uninstalled between the manifest compile and the transaction; running the agent without elevation against services that restrict SERVICE_QUERY_CONFIG.

Related errors


AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21). Data as JSON: /api/errors/84191848ab2ca806. Report an issue: GitHub.