VBS Printer Script that will ignore the local adobe printer

March 30, 2012 at 14:58:20
Specs: Windows 7 & XP
So my situation is the building I work in has re-organized everything, new departments, computers moved, printers moved, etc. So there are a lot of printers that we are going to rename and what not. I have so far made a script that works for Windows 7 and XP environment and will remove all printers and add new ones according (in a hidden window). But the one issue left is deleting all the printers deletes people's Adobe PDF printer. If anyone know's how to write an exception rule that will work in my VBS script it would be a HUGE help. Here is my code thus far:
(server and printer names have been changes for my post)

'objShell allows cscript to run in a vbs file
Set objShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")

'Removes all network printers. ",0" hides CSCRIPT window from being displayed
objShell.run("CSCRIPT %windir%\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -x"),0
objShell.run("CSCRIPT %windir%\System32\prnmngr.vbs -x"),0


'Adds delay to allow time for cscript to run
WScript.Sleep 20000

'Add specific network printers
objNetwork.AddWindowsPrinterConnection "\\server\printer0"
objNetwork.AddWindowsPrinterConnection "\\server\printer1"
objNetwork.AddWindowsPrinterConnection "\\server\printer2"


'Adds delay to allow time for network driver to install
WScript.Sleep 10000

'Sets default printer
objNetwork.SetDefaultPrinter "\\server\printer0"


See More: VBS Printer Script that will ignore the local adobe printer

Report •


#1
March 30, 2012 at 15:40:40
I'm not seeing any reference to the deleting of printers.

How To Ask Questions The Smart Way


Report •

#2
March 30, 2012 at 15:57:40
I have the code commented. This is the part that removes the printers. The first line is for Win7 the second for WinXP since prnmngr.vbs is in different locations in XP and 7.

'Removes all network printers. ",0" hides CSCRIPT window from being displayed
objShell.run("CSCRIPT %windir%\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -x"),0
objShell.run("CSCRIPT %windir%\System32\prnmngr.vbs -x"),0


Report •

#3
March 30, 2012 at 16:34:12
No it doesn't. It calls two other scripts. With a hidden CScript window. Instead of WScript, which has no window to hide.

As far as I know, both script print, "I am the awesomest!" over and over again.

How To Ask Questions The Smart Way


Report •

Related Solutions

#4
March 30, 2012 at 16:54:54
prnmngr.vbs is built with Windows. If you search Windows help for prnmngr you will see. The -x attribute removes all printers and the ,0 runs them in hidden windows.

Report •

#5
March 30, 2012 at 19:16:06
. . . You're not getting my hints, are you? I know, I know. They're subtle, like me. I was going to ask, "Hey, what do you think about my car? I drive a Dodge." and immediately follow it up with a picture of a Ferrari. I didn't because it's more effort than I care to put into a joke 95% won't get because they don't have images enabled.

So instead, I'll post something that perfectly expresses why I find this thread so annoying.

C:\Windows>dir /s /b prnmgr.vbs
File Not Found
You should probably assume I'm familiar with the WScript.Shell.Run documentation, too.

How To Ask Questions The Smart Way


Report •

#6
March 30, 2012 at 23:26:51
No, I'm really not getting you're hints. Looking at what you wrote I'm even more confused. Per http://technet.microsoft.com/en-us/... there is no /b paramater, the .vbs file is spelled wrong and if you're looking in C:\Windows then you're looking in the wrong directory.

Either way if you run what I wrote you know it works, so I don't know why you are arguing what's in there. My questions still remains can you delete all printers to allow a broad script, but still all an argument to keep an Adobe PDF printer if it is present.


Report •

#7
March 31, 2012 at 06:55:36
Per http://technet.microsoft.com/en-us/... there is no /b paramater
Wrong page.

the .vbs file is spelled wrong
I copied and pasted from the script you do provide.

if you run what I wrote you know it works
I get prnmgr.vbs not found. That's my entire point.

Every thread has 10 to 15 seconds to gain my interest. 15 seconds, just 15 seconds. Why did you spend yours arguing that blue is a peculiar shade of yellow?

How To Ask Questions The Smart Way

EDIT: ↓ Not really; you wasted your 15 seconds. ↓


Report •

#8
March 31, 2012 at 12:21:36
You obviously didn't copy and paste because you are missing the letter N! prnmngr <-- See is go nmn in the middle. You only have 1 n hence you will not find a file called prnmgr.vbs because it doesn't exist. But if you look at my code it is spelled correct.. If you're done arguing that and want to offer some assistance with the actual issue I'm having I'd love to hear it,

Report •

#9
April 6, 2012 at 15:15:16
Just encase anyone needs a solution to this I found the solution:

'Deletes only network printers
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * From Win32_Printer Where Network = True")
For Each objPrinter in colInstalledPrinters
objPrinter.Delete_
Next

Set objNetwork = CreateObject("WScript.Network")

'Adds delay to allow time for deletion portion of script to run
WScript.Sleep 20000

'Add specific network printers
objNetwork.AddWindowsPrinterConnection "\\server\printer"
objNetwork.AddWindowsPrinterConnection "\\server\printer"

'Adds delay to allow time for network driver to install
WScript.Sleep 10000
'Sets default printer
objNetwork.SetDefaultPrinter "\\server\printer"


Report •


Ask Question