We help IT Professionals succeed at work.

How do I stop the PushPrinterConnections scripts from running multiple times?

Hello;  weve set up some printers using GPO and the Printer Management functions of R2.  Our problem is that the PushPrinterConnections script runs on the machines every time they boot, whether the machine has the printer already installed or not.  Have any of you run into this problem, and if so, howd you resolve it?   Its not a major issue; but it is generating some noise from users who are in multiple OUs, and getting multiple scripts every day.  Any advice would be appreciated, thanks.
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
Hi, my suggestion would be to modify the script to check EnumPrinterConnections:
http://msdn2.microsoft.com/en-us/library/zhds6k80(VS.85).aspx

         Set WshNetwork = WScript.CreateObject("WScript.Network")
         Set objPrinters = WshNetwork.EnumPrinterConnections
         WScript.Echo "Network printer mappings:"
         For i = 0 to objPrinters.Count - 1 Step 2
            WScript.Echo "Port " & objPrinters.Item(i) & " = " & objPrinters.Item(i+1)
         Next

This way, you would be able to check whether the particular printer has been mapped already, and not map it.  While this still means that you do *run* the script, it won't map printers if they're already there.

Something like:

Set WshNetwork = WScript.CreateObject("WScript.Network")
Set objPrinters = WshNetwork.EnumPrinterConnections
strCurrentPrinters = ";"
For i = 0 to objPrinters.Count - 1 Step 2
      strCurrentPrinters = strCurrentPrinters & UCase(objPrinters.Item(i+1)) & ";"
Next
strPrinterToMap = "\\server\printer"
If InStr(strCurrentPrinters, ";" & UCase(strPrinterToMap) & ";") = 0 Then
      WshNetwork.AddWindowsPrinterConnection strPrinterToMap
End If


Regards,

Rob.

Author

Commented:
Thanks; but we're really looking to try and make it so he script doesn't run at all if they already have the printer(s).  We've tried using WMI filters on the GPO, but so far no luck.


Jason
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
But what is your criteria for not running the script?  You still need to check if they have the printer mapped, right?  So you'll have to run a script (or query, if you like), against the computer anyway, and you may as well do this at the top of the existing script, so you don't to execute "another" script.

I don't see much point in creating another script to check if the printer is installed, and if they are, don't run the extra script, but if not, do run the printer mappings....

Regards,

Rob.

Author

Commented:
Ok, the long and short of it is that we had a Kix logon script that had gotten quite massive over the years; and part of it was deploying printers.  So we started using the R2 Printer Management to deploy them thru group policy.  This works great in 95% of the environment, but we've got some users who are in multiple OU's, and thus get multiple ppc scripts running every morning.

Our original goal was to use the printer management to deploy thru group policy, to cut back on the time users sit staring at scripts in the morning.  Unfortunately, with some users, we've just switched the scripts they're staring at.  That's why we tried using a WMI filter on the GPO, so that if they had the printer, the script wouldn't run at all.  Does that make more sense?

jason
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014
Commented:
Well yes, I does make sense.  I understand that you want scripts to take the least amount of time possible, but to do this, you really have to determine what *is* taking the longest amount of time.

Running a local query like EnumPrinterConnections, and checking string values is going to be a lot faster that re-mapping already mapped printers.  Let's say the first time a user logs in, they will get printers mapped, which will take, say, 15 seconds.  The second time they log on, if you determine that the printer is already installed via EnumPrinterConnections, then you don't run objNetwork.AddWindowsPrinterConnection, and the script would only take about 2 seconds.

Either way, you need some way of determining whether a printer is installed, and this is the only way I know of.

I could help you with other aspects to try to speed things up, if you like.

Regards,

Rob.

Author

Commented:
Thanks for your help.
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
No problem. Thanks for the grade. I hope you get it sorted...

Regards,

Rob.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.