• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Need help with batch file to add network printers to all users.

ctark

Senior member
Microsoft has some built in code you can run from the command prompt to add network printers to all users. The command you use is this

Code:
CSCRIPT %windir%\system32\Printing_Admin_Scripts\en-US\prnmngr.vbs -ac -p "\\server\name"

I have run this code and it works fine. I wanted to make a batch file where it prompts for \\server\name

I thought I had it figured out but everytime I run the code i get an error 1801, which is a connection error. I can just run the CSCRIPT and it installs the printer just fine.

Code:
@Echo Off
set/p p=Printer Name:
CSCRIPT %windir%\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -ac -p "!p!"



PAUSE


I tried google, but I didn't find anything that could really help me. I'm trying to learn a little scripting so I'm starting on small things and hoping to work my way up to more complicated things. If anybody can help I would appreciate it.
 
I'm not familiar with prnmngr.vbs, so I can't comment on what it's looking for, but it sounds like you're not running the command you want to be running.

Assuming the batch file is doing something wrong with your command, you should echo the command to the screen or to a file to see what command you're actually running. Or, in a script this simple you could also just remove the @ECHO OFF line so you can see the commands that are running.

My guess is that using exclamation points instead of percent signs around your variable is causing you to try to add printer !p! instead of the printer you're typing.
 
Prior to using GPO, we used something like this:
"rundll32 printui.dll,PrintUIEntry /q /dn /n\\systemname\printersharename"

Not sure if that helps at all, but I used the above for removal. Should be able to modify to get it to add printers as well.
 
The reason i use the prnmngr.vbs is because it adds network printers to all users on the computer. Sometimes we will get calls from multiple users that use the same computer just to add a printer. The vbs was built into windows for this issue, and it has several other functions as well.

I believe the %p% fixed the issue. Thanks a bunch!
 
The !p! syntax pertains to the ENABLEDDELAYEDEXPANSION option (/V:ON) of CMD.EXE.

In this mode the ! behaves like % except the value of the variable is expanded at execution time instead of when the command(s) are entered.

This mode is disabled by default, and when it is disabled the ! are treated as regular text and do not cause any substitution / expansion.

Snapshot1
 
Back
Top