tech.gate.io blog

Windows Network printer via Logonscript

Background:
The service contract of my old Xerox Workcenter (XM55) ran out(and I'm glad about it)!
A few weeks ago I ordered a new printer DC2250 from “Triumph Adler” aka. Kyocrea KM5050.
So all my users need to get it as the standard printer, but I'm damn lazy so the job have to be done remote.

Lately we got a second printer server, so some of the user use the printer from \\printerserver1 and a few from \\printerserver2. The \\printerserver1 crashes from time to time so I just want to add the new printer on the new printer server and delete the old machine.

Solution:
Servers I use:
\\printerserver1 #Old printer server which crash from time to time
\\printerserver2 # New stable printer server
\\dc #Have a guess, yes this is a MS Domain controller, where the AD is hosted
\\fileserver #network share for the users

old printer is Called Xerox full path \\printerserverX\Xerox
new printer is called Dc2250 full path \\printerserver2\DC2250

As I use the MS Active Directory I can use the Logonscript to get this job done.
If you ain't have a logonscript for your employees now, we will create one. My Test user is called John Dow.
I want to mount the network share, add a printer and set it to the standard printer, and delete the old printer. As you can imaging rename or deleting a printer on the server , while users got it mounted will lead you into trouble, so please don't try it.
Okay let start:

Create a new file called jdow.bat
Now open it in your favorite text editor and copy this:

net use * /del /yes
 rem delete all file shares

 net use h: \\fileserver\%USERNAME%$ /persistent:yes
 rem mount the network share of the user persistent

 net use * \\fileserver\public\sales /persistent:yes
 rem file share e.g. sales dependss on your filestructur

 rem now the printers

 rundll32 printui.dll,PrintUIEntry /q /dn /n\\printerserver1\Xerox 
 rem Printer Xerox at printerserver1 will be deleted
 
 rundll32 printui.dll,PrintUIEntry /q /dn /n\\printerserver2\Xerox 
 rem Printer Xerox at printerserver2 will be deleted

 rundll32 printui.dll,PrintUIEntry /q /in /n\\printerserver2\DC2250
 rem Printer DC2250 added

 rundll32 printui.dll,PrintUIEntry /q /y /n\\printerserver2\DC2250
 rem Printer DC2250 is now standartprinter

 rem now restart the spooler
 net stop spooler 

 net start spooler

 

Now we have a look at the “rundll32 printui.dll,PrintUIEntry” commands we use
/dn – delete a Network printer
/n – name of the printer, full path is needed
/in – install a printer (driver have to be on the printer server)
/q – Quite installation, because we don't want the user to call in to tell us they got some “strange” messages

Be sure that everything is started fine, please restart the spooler service, last two lines of the logonscript. (that should be done not a “have to”).

Script is finished,now we place it to the Standard location on the domain controller
\\dc\NETLOGON\
Make sure that the user can accesse this file, if he can't it won't work

Okay now open the
MMC (Start->Run->mmc)
File → Add/remove Snapin
Add → AD Users and Computer → Add → Close → OK
Expand your domain and search your user (usually in the OU User)
Now got to the profile tab and add the name of the *.bat file youcreatedd (e.g. jdow.bat)
Should look like this:
Image

Congratulation your done it, next time a user logon he get his network shares and the old printer are deleted and the new one appear as standard printer.

 

Post new comment

Anti-Bot verification code image
Try another code

Feeds List