Question

I use to use this script for Windows XP but since we're doing the switchover to 7 I tried to use it on the new images. It seems like it tries but it doesn't work. I have created a 64bit print server and these machines are 64bit which is the only difference. I read up on this and saw there was a GPO that needed to be set to allow this to work. Which was - Computer Configuration > Administrative Templates > Printers > Allow Print Spooler to accept client connections.

I have tried everything and can't get this to work, it doesn't give me an error or anything. It gives me the prompts for PC name and Printer name, then says 'Adding printer' from the echo command, and just sits there. I can run the command by itself and it doesn't work either....... Please help!

The main thing is that the printer needs to be added from a print server and to the computer for all users as their default.

@echo off
echo PC Name 
set /p PC=

echo Printer Name
set /p PRINTER=

ECHO Adding Printer...
\\ghostserver\installs\pstools\psexec \\%PC% -n 3 cmd /c rundll32         
printui.dll,PrintUIEntry /y /ga /c\\%PC% /n\\PRINTSERVER\%PRINTER%

ECHO Restarting Print Spooler...
start /wait sc \\%PC% stop spooler
start /wait sc \\%PC% start spooler
Was it helpful?

Solution

Do you want to install or map the printer from the network ?

First thing to try : map the printer manually on a 7 x64 client. If it fails, your problem is not the batch.

Also try the simple rundll32 printui.dll PrintUIEntry /in n\\PRINTSERVER\%PRINTER% with a non-admin non-elevated account on the client to validate the print server configuration.

Is the "Disallow installation of printer using kernel-mode drivers" GPO disabled ? (Have to be)

Check the firewall settings, UAC/elevation configuration, admin access. Run a gpupdate /force and restart the client.

Check the event log on both the client and print server for any errors.

With an admin account (both print server and client), try to push the installation from the print server.

Have you tried to force adding the provider ? /j "LanMan Print Services"

If you have 2008 servers or DCs, you can use Print Management or Group Policy Preferences to deploy printers (easier than bat+psexec+printui.dll).

If you really want to do it via login script, there are also a bunch of tools in Vista/7/8 for print management in %WINDIR%\System32\Printing_Admin_Scripts, like this one.

Side note : start /wait is inefficient since sc.exe doesn't wait any response of the service. So, if you stop and start without a pause, chances are the service will not be stopped before the restart and skip the second order. You have to simulate a pause (ping 127.0.0.1 -n 5 >nul 2>&1) between stop & start or use a safer script to check the state of the service.

OTHER TIPS

Thank you so much! That fixed it.

Here's my add script:

@echo off
echo PC Name
set /p PC=


echo Printer Name
set /p PRINTER=


echo Adding Printer...
\\servername\installs\pstools\psexec -s -i -accepteula \\%pc% rundll32 printui.dll PrintUIEntry /in /y /ga /n\\PRINTSERVER\%PRINTER%


echo Restarting Print Spooler...
start sc \\%pc% stop spooler
pause
start sc \\%pc% start spooler
pause

Here's my remove script:

@echo off
echo PC Name
set /p PC=

echo Printer Name
set /p PRINTER=


echo Adding Printer...
\\servername\installs\pstools\psexec -s -i -accepteula \\%pc% rundll32 printui.dll PrintUIEntry /gd /n\\PRINTSERVER\%PRINTER%


echo Restarting Print Spooler...
start sc \\%pc% stop spooler
pause
start sc \\%pc% start spooler
pause
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top