Link to home
Start Free TrialLog in
Avatar of rimmena
rimmena

asked on

Script or utility to unshare a printer

I have recently installed Adobe Standard Writer 9.0 and as part of the installation it installs the printer driver and then shares it out.
I want the driver but I don't want it shared. Is there either a VBscript or utility that will remove the share ?
I need to deploy to multiple PC's so doing this manually is a no go.
Avatar of WindowsITAdmin
WindowsITAdmin
Flag of Spain image

Hi.

Maybe something like that (i don't prove it):

strComputer = "."
strprinter = ""
Set objWMIService = GetObject("winmgmts:\\"  & strComputer & "\root\cimv2")
Set colInstalledPrinters =  objWMIService.ExecQuery _
    ("Select * from Win32_Printer")
For Each objPrinter in colInstalledPrinters
    If objPrinter.name="Printer_Name" Then
           obPrinter.Shared=False
    End If
Next

You can find examples of VBS with printers in http://gallery.technet.microsoft.com/ScriptCenter/en-us/site/search?f[0].Type=SearchText&f[0].Value=printers&pageIndex=1

Hope this helps.
Avatar of rimmena
rimmena

ASKER

Does not remove it. I'll have a look at that link you mentioned.
Do you change Printer_Name for the name of your printer at line   If objPrinter.name="Printer_Name" Then?
Avatar of rimmena

ASKER

Yes.
Try running:

strComputer = "."
strprinter = ""
Set objWMIService = GetObject("winmgmts:\\"  & strComputer & "\root\cimv2")
Set colInstalledPrinters =  objWMIService.ExecQuery _
    ("Select * from Win32_Printer")
For Each objPrinter in colInstalledPrinters
    Wscript.Echo objPrinter.Name
Next

To be sure that it can "read" the names of the printers and find the exact name of the printer you are searching.
Avatar of rimmena

ASKER

This is weird, I can read the name with no issues, but the other script will not remove the sharing. Tried stopping and starting the print spooler as well
There was an error in the script
strComputer = "."
strprinter = ""
Set objWMIService = GetObject("winmgmts:\\"  & strComputer & "\root\cimv2")
Set colInstalledPrinters =  objWMIService.ExecQuery _
    ("Select * from Win32_Printer")
For Each objPrinter in colInstalledPrinters
    If objPrinter.name="Printer_Name" Then
           objPrinter.Shared=False
    End If
Next

Try this please, the other says "obPrinter.Shared=False"
Avatar of rimmena

ASKER

I spotted that and corrected it. Still no go :-(
Damn it.

Okey, then I only know one way to do it. At the registry in Hkey_local_machine\system\currentcontrolset\control\print\printers\ are a key for every printer installed on the computer. Inside there are the keys that configure the printer. You can compare the values with the printer shared and without it and if you find the difference we can make a script that modifys it.

Hope this helps.
ASKER CERTIFIED SOLUTION
Avatar of WindowsITAdmin
WindowsITAdmin
Flag of Spain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rimmena

ASKER

Excellent, that worked a treat. So does the .Put_ apply it or something ?
Yes, the changes you made to the object objPrinter were not apply until you make the Put.

Pleased to help you.