Jump to content

How do you share a printer programatically?


Recommended Posts

I've searched high and low (Google and MSFN Forum that is!) but can't find any command to share a printer without resorting to reg hacking (Not sure if even that can be done yet). NET SHARE seems to be the closest thing but for printers the only option is to delete shares and this doesn't even seem to work properly either (The share is still active according to Control Panel->Printers And Faxes).

Help would be appreciated.

Thanks.

Link to comment
Share on other sites


Here is a VBS script that is supposed to share all printers on the network

Here is the link to the article where I found this script.

Hey Script Guys Share Printer

'''' This is for XP/2003 only

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colInstalledPrinters = objWMIService.ExecQuery _

("Select * from Win32_Printer Where Network = FALSE")

i = 1

For Each objPrinter in colInstalledPrinters

objPrinter.Shared = TRUE

objPrinter.ShareName = "Printer" & i

objPrinter.Put_

i = i + 1

Next

Link to comment
Share on other sites

WOW! Thanks that was a quick response!! I started looking at printui.dll which might have worked if I installed the printers using this command instead of integrating them which is not ideal.

Just tried the script and it works fine. Just need to change the share names to something a little more meaningful.

Thanks very much.

Link to comment
Share on other sites

here try it this way

' these comment out the line in the script so they dont get read while the script is active.

'''' This is for XP/2003 only

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colInstalledPrinters = objWMIService.ExecQuery _

("Select * from Win32_Printer Where Network = FALSE")

i = 1

For Each objPrinter in colInstalledPrinters

objPrinter.Shared = TRUE

objPrinter.ShareName = "Printer" & i

'If 'objPrinter.ShareName = "Place The PrinterName Here"

'objPrinter.Put_

'exit for

'End If

i = i + 1

Next

Link to comment
Share on other sites

Actually the names do not need to be more meaningful as the Printer UI shows the full name of the printer anyway.

I'm adding the connection to my client machine like this but it seems to always prompt 'You are about to connect to a printer on a server' :

rundll32 printui.dll PrintUIEntry /in /n\\server\printer1

I've tried the options /q /Gw to try to suppress them but doesn't seem to make any difference.

I'll dig around further.

Edited by Dobby
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...