[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 244
  • Last Modified:

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?
0
TMG255
Asked:
TMG255
  • 4
  • 4
1 Solution
 
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now