Disable Printer Sharing

Jason
Contributor

There was a post i saw from 2012 that mentioned you could disable Printer Sharing with "cupsctl --no-share-printers"

That doesn't really uncheck and grey out the "Printer Sharing" service though. Is there a way to lock it down? Internet Sharing was easy enough with com.apple.nat

14 REPLIES 14

geoffrey-obrien
New Contributor

I use the cupsctl method, but I also install all our printers via a script and set the sharing option to off during that process as well.

KCH080208
New Contributor II

What does that script look like? @geoffrey-obrien

bentoms
Honored Contributor III
Honored Contributor III

rtrouton
Valued Contributor III

I've got a script that I use to disable printer sharing for individual printers after they've been set up. It's available from here on my Github repo:

https://github.com/rtrouton/rtrouton_scripts/tree/master/rtrouton_scripts/Casper_Scripts/disable_pri...

rmanly
Contributor III

This will disable sharing on all currently installed printers. Not just known/named ones.

https://gist.github.com/rmanly/bf28847ddec8e3f0bd03

#!/bin/bash

while read -r _ _ printer _; do
    /usr/sbin/lpadmin -p "${printer/:}" -o printer-is-shared=false
done < <(/usr/bin/lpstat -v)

tcandela
Valued Contributor

To implement this in Casper it says to use the Files and Processes option when making a policy

The last option within Files and Processes is Execute command, so you would paste the command into the field and once your printer is installed, the command will execute and remove the sharing on that printer only.

lpadmin -p <printer_name> -o printer-is-shared=false

would I need to put the <printer_name> in quotes "MY Printer is"

mm2270
Legendary Contributor II

@tcandela - generally speaking when talking about unix commands, its a good idea to quote strings, especially if there are spaces in them. If your printer name has spaces in it then definitely enclose it in quote marks.

tcandela
Valued Contributor

I am going to stick the command in the Files and Processes Execute section, here is the command my printer name has spaces
lpadmin -p "My Printer name" -o printer-is-shared=false

If i wanted to use this in a script instead, what priority would i use ?
In Casper Admin I have a 'Script' category set at 15, priority 'After'

#!/bin/bash
# A HARDCODED VALUE FOR "Printer_Name" CAN BE SET BELOW.
#
# Delete the double quotes and replace with the desired printer_name,
# This script disables printer sharing on a designated printer.
# If this script is to be deployed via policy using the JSS leave the next line as is.

printer_name="$4"
lpadmin -p "$printer_name" -o printer-is-shared=false
echo "Print Sharing for $printer_name has been disabled."
exit 0

mm2270
Legendary Contributor II

@tcandela - A Category's priority has no bearing on how the script or package will run when its in that category. It only affects where the Category label shows up within Self Service.

tcandela
Valued Contributor

when the script runs via Casper, were does the echo "message" get displayed? or is it just ignored?

when i run the script from the command line, i see the echo 'message' in the terminal

gulibrary
New Contributor

@tcandela

when the script runs via Casper, were does the echo "message" get displayed? or is it just ignored?

You'll see it in the logs on the JSS.

JayDuff
Contributor II

These solutions all disable sharing, at the printer level. I believe the OP wanted to know how to Disable (and gray out) the Printer Sharing checkbox in the Sharing Preference Pane.

fdeltesta
New Contributor III

Hello, @JayDuff Your suggestion is indeed something I am actually trying to find. Do you or anybody have a clue ? I have though about disabling the general printer sharing options and then hiding the "sharing" section from the preference panel but not so happy with that solution...

JayDuff
Contributor II

@fdeltesta Sorry - what's here is the best I found.