/// <summary> /// Sets the printer attributes for the specified print queue to the specified value. /// </summary> /// <param name="queue">The <see cref="PrintQueue" /> to modify.</param> /// <param name="attributes">The <see cref="PrintQueueAttributes" />.</param> /// <remarks> /// Print queue attributes can be retrieved (read-only) from a property on the <see cref="PrintQueue" /> object. /// This is why there is no symmetrical "GetPrinterAttributes" method. /// </remarks> internal static void SetPrinterAttributes(PrintQueue queue, PrintQueueAttributes attributes) { RegistryKey printer = Registry.LocalMachine.OpenSubKey(_printersSubKey).OpenSubKey(queue.FullName, true); printer.SetValue("Attributes", (int)attributes); printer.Close(); }
/// <summary> /// Changes the attributes of the specified print queue. /// </summary> /// <param name="printQueue">The <see cref="PrintQueue" /> to modify.</param> /// <param name="attributes">The attributes to modify.</param> /// <param name="setAttributes">if set to <c>true</c> add the specified attributes; otherwise, remove those attributes.</param> /// <exception cref="ArgumentNullException"><paramref name="printQueue" /> is null.</exception> public static void ChangeAttributes(PrintQueue printQueue, PrintQueueAttributes attributes, bool setAttributes) { if (printQueue == null) { throw new ArgumentNullException(nameof(printQueue)); } PrintQueueAttributes originalAttributes = printQueue.QueueAttributes; PrintQueueAttributes modifiedAttributes = setAttributes ? originalAttributes | attributes : originalAttributes & ~attributes; if (modifiedAttributes != originalAttributes) { PrintRegistryUtil.SetPrinterAttributes(printQueue, modifiedAttributes); // The print spooler must be restarted for this change to take effect. PrintSpooler.RestartSpooler(); } }