# # Author:: Paul Morton () # Cookbook:: windows # Resource:: auto_run # # Copyright:: 2011-2018, Business Intelligence Associates, Inc. # Copyright:: 2017-2018, Chef Software Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # chef_version_for_provides '< 14.0' if respond_to?(:chef_version_for_provides) resource_name :windows_auto_run property :program_name, String, name_property: true property :path, String, coerce: proc { |x| x.tr('/', '\\') } property :args, String property :root, Symbol, equal_to: %i(machine user), default: :machine alias_method :program, :path action :create do data = "\"#{new_resource.path}\"" data << " #{new_resource.args}" if new_resource.args registry_key registry_path do values [{ name: new_resource.program_name, type: :string, data: data, }] action :create end end action :remove do registry_key registry_path do values [{ name: new_resource.program_name, type: :string, data: '', }] action :delete end end action_class do # determine the full registry path based on the root property # @return [String] def registry_path { machine: 'HKLM', user: 'HKCU' }[new_resource.root] + \ '\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run' end end