class Chef::Resource::WindowsPrinter
Constants
- PRINTERS_REG_KEY
Public Instance Methods
create_printer()
click to toggle source
creates the printer port and then the printer
# File lib/chef/resource/windows_printer.rb, line 112 def create_printer # Create the printer port first windows_printer_port new_resource.ipv4_address do end port_name = "IP_#{new_resource.ipv4_address}" declare_resource(:powershell_script, "Creating printer: #{new_resource.name}") do code <<-EOH Set-WmiInstance -class Win32_Printer ` -EnableAllPrivileges ` -Argument @{ DeviceID = "#{new_resource.device_id}"; Comment = "#{new_resource.comment}"; Default = "$#{new_resource.default}"; DriverName = "#{new_resource.driver_name}"; Location = "#{new_resource.location}"; PortName = "#{port_name}"; Shared = "$#{new_resource.shared}"; ShareName = "#{new_resource.share_name}"; } EOH end end
delete_printer()
click to toggle source
# File lib/chef/resource/windows_printer.rb, line 137 def delete_printer declare_resource(:powershell_script, "Deleting printer: #{new_resource.name}") do code <<-EOH $printer = Get-WMIObject -class Win32_Printer -EnableAllPrivileges -Filter "name = '#{new_resource.name}'" $printer.Delete() EOH end end
printer_exists?(name)
click to toggle source
does the printer exist
@param [String] name the name of the printer @return [Boolean]
# File lib/chef/resource/windows_printer.rb, line 74 def printer_exists?(name) printer_reg_key = PRINTERS_REG_KEY + name logger.trace "Checking to see if this reg key exists: '#{printer_reg_key}'" registry_key_exists?(printer_reg_key) end