Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account



Photo

How do you share a printer programatically?

- - - - -

  • Please log in to reply
5 replies to this topic

#1
Dobby

Dobby

    Member

  • Member
  • PipPip
  • 258 posts
  • Joined 17-May 04
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.


How to remove advertisement from MSFN

#2
gunsmokingman

gunsmokingman

    MSFN Master

  • Super Moderator
  • 2,421 posts
  • Joined 02-August 03
  • OS:none specified
  • Country: Country Flag
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




GunSmokingMan



#3
Dobby

Dobby

    Member

  • Member
  • PipPip
  • 258 posts
  • Joined 17-May 04
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.

#4
gunsmokingman

gunsmokingman

    MSFN Master

  • Super Moderator
  • 2,421 posts
  • Joined 02-August 03
  • OS:none specified
  • Country: Country Flag
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




GunSmokingMan



#5
Dobby

Dobby

    Member

  • Member
  • PipPip
  • 258 posts
  • Joined 17-May 04
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, 09 October 2005 - 01:41 PM.


#6
Dobby

Dobby

    Member

  • Member
  • PipPip
  • 258 posts
  • Joined 17-May 04
Seems like someone else had the same problem:

from http://www.msfn.org/...ndpost&p=172024

Printer.vbs
Set WshShell = WScript.CreateObject ("WScript.Shell")
WshShell.Run ("rundll32 printui.dll,PrintUIEntry /in /n\\studeerkamer\samsung /q")
WScript.Sleep 5000
WshShell.SendKeys "{ENTER}"
WScript.Quit

Thanks again for your help.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users