Automating Printer Installation

If I add a printer to the server and want to share it with everyone in the company, is there a way to have the log on script automatically grab the information and add it or do I have to add it manually to the script?
TMG255Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

 
Shift-3Commented:
It would be possible to write a vbscript which would query for all shared printers on a particular server and then map them for the current user.  Would that meet your requirements?
0
 
TMG255Author Commented:
That seems to be what I am looking for. Would you have an example script by chance or somewhere I can find one?
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Shift-3Commented:
Paste the script below into a text file with a .vbs extension.  Customize the value of the strPrintServer variable on line 3 with the name of your print server.  Running the script will map all printers shared from that server for the current user.


On Error Resume Next
 
strPrintServer = "servername"
strQuery = "SELECT * FROM Win32_Printer WHERE Shared = True"_
    & " AND Network = False"
    
Set objNetwork = CreateObject("Wscript.Network")
Set objWMIService = GetObject("winmgmts:\\" & strPrintServer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery(strQuery)
 
For Each objItem In colItems
    strShare = "\\" & strPrintServer & "\" & objItem.ShareName
    objNetwork.AddWindowsPrinterConnection strShare
Next

Open in new window

0

Experts Exchange Solution brought to you by ConnectWise

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
 
TMG255Author Commented:
I changed line 3 and ran the script from the command line but nothing happened. Never got the printers. Any ideas?
0
 
Shift-3Commented:
Put an apostrophe at the beginning of line 1 and see if any errors appear.
0
 
TMG255Author Commented:
ok t is working now. The question I have now is... how do I get it so that it doesn't try to install the printer everytime it runs the script.  (this is a windows 7 computer, doesn't seem to happen in XP) Is there a way to tell it to disregard if printer is already installed?
0
 
Shift-3Commented:
Well, I don't have a Windows 7 box to test on.  The previous script works fine for me in XP and Vista.

In any case, this modification should only map printers which are not currently mapped.


On Error Resume Next
 
strPrintServer = "servername"
strLocalQuery = "SELECT DeviceID FROM Win32_Printer WHERE Network = True"
strRemoteQuery = "SELECT ShareName FROM Win32_Printer WHERE Shared = True"_
    & " AND Network = False"
    
Set objMapped = CreateObject("Scripting.Dictionary")
objMapped.CompareMode = VbTextCompare
 
Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
Set colItems = objWMIService.ExecQuery(strLocalQuery)
 
For Each objItem In colItems
    objMapped.Add objItem.DeviceID, ""
Next
    
Set objNetwork = CreateObject("Wscript.Network")
Set objWMIService = GetObject("winmgmts:\\" & strPrintServer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery(strRemoteQuery)
 
For Each objItem In colItems
    strShare = "\\" & strPrintServer & "\" & objItem.ShareName
    
    If Not objMapped.Exists(strShare) Then
        objNetwork.AddWindowsPrinterConnection strShare
    End If
Next

Open in new window

0
 
TMG255Author Commented:
it works great but with xp if the printer is installed already it does not try to install it everytime i log in. where as with windows seven it attempts to install the printer everytime which shows a pop and sits for approx 1 min on the screen. Users will be confused by this.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.