# How to Create a Batch file to install Network Printers



## sono708 (Mar 27, 2015)

Hi Everyone,

I'm new to batch files but I want to create a batch file to run at startup on Windows 7 so when a user logs in with there username and password into the network to see if the Xerox 7535 network printer is installed and if it isn't to install it.

Now because these are computers that multiple users use frequently if I were to do this manually I would need the user to login to the network with there credentials and then open a window and type in //printer_server_name/ and a window would pop up and again they would have to type in there network credentials (username & password) then select the printer Xerox 7535 printer and right click on it and select connect and it would install the printer drivers if needed.

Now when I login as administrator to the computer I can connect to the printer server but when I try to connect/install to the Xerox 7535 printer it doesn't install and I get Error:"0x0000052e so instead I have to have each user login into the computer and install the printer which works that way.

I'm open to any other ways of doing this and I really appreciate the help.

Thanks,

Bill


----------



## CleaverX (Sep 27, 2012)

You can assign a logon script to each user on each computer, the script would be something like this:



 
 Our example configure_printers.vbs script has the following:
_Dim net_
_Set net = CreateObject("WScript.Network")_
_net.AddWindowsPrinterConnection "__\\util-2\print-brother-1__"_
_net.AddWindowsPrinterConnection "__\\util-2\print-hpphoto-1__"_
_' Set the default printer now_
_net.SetDefaultPrinter "__\\util-2\print-hpphoto-1__"_

Save the file with a .vbs extension

*To assign a logon script to a user or group*


Open Computer Management. 
In the console tree, click Users. 
 Where? System Tools/Local Users and Groups/Users


Double-click the user to which you want to assign a logon script. 
Click the Profile tab. 
In the Logon script field, enter the path and name of the logon script you want to assign to that user, and then click OK. 
 

You can place a single copy of the script somewhere inside the Public user directory or you will need to place individual copies inside each user's subdirectory but bury it deep enough so the users won't accidentally delete it.


----------



## sono708 (Mar 27, 2015)

Thanks CleaverX,

The .vbs script works if I just run it on the computer.

But when I go to Computer Management -> Local Users and Groups -> none of the network users are listed just local users and I just want any network user even if they haven't logged into the computer before to install the network printers at startup and is there a way delete the old printers.

Thanks,

Bill


----------



## CleaverX (Sep 27, 2012)

Not sure what you need by network users. If these are domain users then you must place the logon script in ADUC so it will work no matter which machine they logon to.


As for removing them, I found this example online:


Example:
net.RemovePrinterConnection ("\\curricsvr\ictmono", true, true)

bForce : Force the removal of the mapped printer. 
(Boolean Optional, default = false). 

bUpdateProfile : Save changes in the user's profile
(Boolean Optional, default = false)


----------



## sono708 (Mar 27, 2015)

Hi CleaverX,

Yes I mean domain users.

How do you run it in AD?

I don't want it to run on all the computers a user logs into but I do have an AD OU group were the computers are listed that I want the vb script to run on but I don't know how to do it since I'm new to this and I greatly appreciate your help.

I ran the removal script but it did work and I get this error: "Cannot use parentheses when calling a Sub"

Also, I ran this example below and it didn't work as well and received the same error message as above:

' Disconnecting a network printer
Set PrinterPath = "\\print_server\printers"
Set objNetwork = WScript.CreateObject("WScript.Network") 
objNetwork.RemovePrinterConnection (PrinterPath, true, true)


----------



## CleaverX (Sep 27, 2012)

Well in that case, why not read this excellent primer:

http://www.petri.com/setting-up-log...ctory-users-computers-windows-server-2008.htm


----------

