Jump to content

Setting Printers Based On Room Location


Recommended Posts

Posted

Hello All,

 

Does anyone have any scripts that set printers based on room location.

 

My Scenario:

 

We have 6 IT Suites in each one a colour laser and mono laser, when a person (does not matter who) logs onto a machine in that room the printers in the will be mapped and made available.

 

All printers are network'd.

 

Ideally I would like to set the printers via GPO but have not yet found a way to do this but given time...... ;-)

 

Any pointers would be cool.

 

Oh Yeah, each machine have a unique name and the computer description has the following "Room XX - PC XX"

Posted
Heh, don't worry about it. BTW, if you get stuck feel free to post. I've hacked Rics script to bits to do what I wanted. I'm sure you'll end up in the same boat. :D
Posted

Geoff,

 

After a heck of alot of digging I have found that the computer description is held in the registry.

 

I have used Ric's script as a basis and added a registry lookup to get the computer description (ours are set as Room XX - PC XX, and PC names are all unique as per the counties naming convention).

 

Anyhow as we are only reading a reg key no special permissions are required so finally (after about 3 weeks of hunting) I can get the printers sorted ;-)

Posted

@ChrisH: I agree you can query the AD but that requires special permissions and although you can impersonate in some cases a username and password must be supplied. Not happy about providing those in plain text.

 

@Ric_ & Gecko: I am testing the script within the school now and will post up later today.

Posted
I havent tested it but I would have thought it would have worked in the context of a log on script. My log in script querys ad for group membership with no problem. It must be different for computer objects I take it?
Posted

I haven't read the links but this is a quick and basic way to get a network printer added.

 

If you type

 

%systemroot%\system32\rundll32.exe printui.dll,PrintUIEntry /ga /n \\SERVER_NAME\PRINTER_NAME

 

in a command prompt it will add the printer for all users who log on to that PC.

 

It does mean you need to do it on each computer and redo everytime you change the share name but is simple enough to add that line to a logon script, for each room (OU) of computers throgh Group Policy and AD, if you want.

Posted

WE use a VBS script. Specifies a specific printer based on the room and machine name.

 

Machine name a1-01-XX (xx being the machine number in room A1-01)

 

To see the properly better paste in to notepad.

 

rem Printer Mapping Script

 

Const NetworkMapped = "\\"

On Error Resume Next

 

Set objNetwork = CreateObject("WScript.Network")

 

Set colPrinters = objNetwork.EnumPrinterConnections

For i = 0 to colPrinters.Count -1 Step 2

strPrinterName = colPrinters.Item(i)

strPrinterUNC = colPrinters.Item (i + 1)

If Left(strPrinterUNC,2) = NetworkMapped Then objNetwork.RemovePrinterConnection(strPrinterUNC)

Next

 

'And now to map the required printers

'Capture the Computer name, take the first 5 characters to determine the classroom

'Then map the relevant printers for that classroom

 

strComputerName = Left(objNetwork.ComputerName, 5)

Select Case strComputerName

Case "A1-01"

bjNetwork.AddWindowsPrinterConnection "\\servername\printername"

objNetwork.SetDefaultPrinter "\\servername\printername"

 

End Select

 

If you need add more insert more lines add them in before the end select command. The number 5 specifies the number of characters to use from the start of the name. So 3 would pick up in our case "A1-"

 

Hope this helps

Posted
I haven't read the links but this is a quick and basic way to get a network printer added.

 

If you type

 

%systemroot%\system32\rundll32.exe printui.dll,PrintUIEntry /ga /n \\SERVER_NAME\PRINTER_NAME

 

in a command prompt it will add the printer for all users who log on to that PC.

 

It does mean you need to do it on each computer and redo everytime you change the share name but is simple enough to add that line to a logon script, for each room (OU) of computers throgh Group Policy and AD, if you want.

 

This is roughly what I use - but I put a little txt file on each PCs C: drive and then set the printer depending on what the name of the txt file is - so for example in the IT Suite its IT.txt, and the printer line does an IF EXIST (I think) and runs if the name matches - so theres a bat file that runs through about 30 printers at login - but its very quick. You can add the /y argument to set as default too.

 

See - http://www.robvanderwoude.com/index.html

Posted

I'd use the method mentioned above with the printui.dll

 

put all yout workstations in OUs by Room

 

On the workstation policy (computer configuration) / windows settings / Scripts / Startup script

 

add a batch file with the relevant printers for that room, using the printui.dll method.

 

All you need to do to give a computer the right printers is move it into the relevant OU. All the users that logon will get printers specific to that room.

  • 1 month later...
Posted

OK. These posts are really great- we have some VB scripts running (kind of) and set up by CSE engineers in the past; there's a utility we have in their software that sets these to autorun at login. They worked until last week, and now they sometimes work and sometimes don't. Pathetic really.

 

Not being a scripter myself, could someone tell me where to put Ric's excellent script so that I can modify it and test it? I know Group Policy pretty well and I'm aware that logon scripts can go in the "Startup Script" section, but once in my SYSVOL/Scripts folder do I merely browse for the file in the GPO or paste the actual contents in there (as I was told to do this week)?

 

Basically I want the script to check the first 4 letters of the location and choose a default printer from there (e.g. ICT 6 ICT 5 etc etc). Am I right in assuming that since Ric's script chooses the default location based on station name that I could drop it in at the top-level of the Stations OU we have rather than appying it to each OU??

 

/Ramble

 

Thanks!

 

Paul

Posted
Not being a scripter myself, could someone tell me where to put Ric's excellent script so that I can modify it and test it? I know Group Policy pretty well and I'm aware that logon scripts can go in the "Startup Script" section, but once in my SYSVOL/Scripts folder do I merely browse for the file in the GPO or paste the actual contents in there (as I was told to do this week)?

 

I put mine in netlogon and browse for it in GP. I think there is a default location where scripts go otherwise 'per policy'. I'm sure you could put it pretty much where you wanted, but you'd have to get the permissions right - obviously sorted if it goes in netlogon!

 

Basically I want the script to check the first 4 letters of the location and choose a default printer from there (e.g. ICT 6 ICT 5 etc etc). Am I right in assuming that since Ric's script chooses the default location based on station name that I could drop it in at the top-level of the Stations OU we have rather than appying it to each OU??

 

Exactly right, but I think you'll find you need to put your script in the Logon Scripts policy under User Config (but for the machine's policy!)

 

:)

 

Andy.

Posted

Here's my updated script which checks the first four characters of the computer name. Simply change the characters that are searched for in the case statement and the printer shares accordingly (more can be added before the 'case else' statement).

 

I tend to keep the script in the NETLOGON share and it is applied by GPO on the Users OU (inside which I have OUs for staff and pupils). The script should be run as a login script - not a startup script. Don't run it as an admin or on the print server as all the printers will disappear from your server!

printers_167.vbs

Posted
Here's my updated script which checks the first four characters of the computer name. Simply change the characters that are searched for in the case statement and the printer shares accordingly (more can be added before the 'case else' statement).

 

I tend to keep the script in the NETLOGON share and it is applied by GPO on the Users OU (inside which I have OUs for staff and pupils). The script should be run as a login script - not a startup script. Don't run it as an admin or on the print server as all the printers will disappear from your server!

 

We would be willing to try this, however, does the VB script delete all of the network printers if a teacher was to log onto their laptop where the printers are all set up (i.e. networked photocopiers). Also does this script take very long to run?

 

We are currently using the rundll method but have found that this sometimes does not work properly and want to see if there is anything else out there.

Posted

have never had any problems with the rundll method using a batch script that features lots of sections like:

 

if %computername:~0,3% == A8- (

rundll32 printui.dll,PrintUIEntry /in /n \\print1\A8Laser

rundll32 printui.dll,PrintUIEntry /y /n \\print1\A8Laser /q

echo A8 Printer connected.

goto END

)

 

ideally best 2 have 2 identical print servers so if there's a problem with one u can just alter the batch script so printers are mapped from the other.

Posted

An old Microsoft NT4 tool exists called Con2Prt.exe which connects and disconnects printers via a DOS command line command.

 

Using this utility as described will provide a user with a list of printers available to the workstation they are logging on at. The list of available printers and the default printer can be defined per machine usually on a room basis.

 

You just put a variable on it and its a doddle to use - here is a good link with instructions and how to get it

 

http://www.rangersuite.com/support/knowledgebase/articles/index.asp?article=KB0204270#using%20the%20nt%20tool%20con2prt.exe

Posted
have never had any problems with the rundll method using a batch script that features lots of sections like:

 

if %computername:~0,3% == A8- (

rundll32 printui.dll,PrintUIEntry /in /n \\print1\A8Laser

rundll32 printui.dll,PrintUIEntry /y /n \\print1\A8Laser /q

echo A8 Printer connected.

goto END

)

 

ideally best 2 have 2 identical print servers so if there's a problem with one u can just alter the batch script so printers are mapped from the other.

 

I like this method! How do you find the switches for that command?

Posted

I've got a really good script that will do exactly this, you can add the variable that says if the computer name starts with "xxx" then add a printer "xyz" as the default

 

Will send it on Monday when I get back into work

 

Regards

 

Matt

Posted
@luke213: Simply edit the script so that it behaves differently for computers named and have it not run the remove printers section. An if.. not statement should do the trick.
Posted

First thing to say is Hi! (First post)

 

I just thought I would make a couple of comments as I used a similar script where I work.

 

I spent a number of hours when I first used a vbs script to add printers trying to work out why they appeared but didn't always work. If you are only a domain user, you are allowed to add printers via a vbs script, but you aren't allowed to install the drivers. If this is the case, you get attached to the network printer but can't actually print, you get a nice error instead.

 

The way I get around printer drivers is to run a slighly modified version also as the startup script. As this script runs as system, it is allowed to install new drivers, then when the user logs in, they don't need to install drivers and it all works.

 

One other thing I would mention is that I have "wsh.sleep 5000" between adding a printer and making it default, sometimes it takes a second or two to finish adding the printer, and with multiple printers the default command sometimes is run before the printer exists.

 

 

 

I also have a WMI script that removes the Microsoft Document imager if anyone is interested, you can't seem to access it via vbs as it has a funny name.

 

David

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...