Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Logon Script - Map printer by location 1

Status
Not open for further replies.

mswilson16

Programmer
Nov 20, 2001
243
0
0
US
I have a windows 2000 domain, I have 5 different physcial location on the same network. Each location has different printers. I have users that will go to each location within the same week.

I have roaming profiles setup and I am getting the complaint that as much as there documents follow them, they cant print because they have just got one default printer that is mapped using con2prt from a log on script.

All users are within the same OU and people from one department can go to many places... is there a way for me to get the logon script to know where they currently are? I was thinking of naming the machines in such a way, so the log on script could check the machines names then map the right printers... is this possible?

Thanks in advance

Mswilson
 
I have the same problem and at the moment have installed printer locally on each machine on tcp/ip port but it means we now have no central control over print queues/quotas etc. Someone suggested to me printer location tracking but as i understand it i would have to make each computer room on a different subnet so i could implement it?

If anyone has any better ideas i too would be extremley grateful as this is driving me nuts!!


Lindsay
 
You need to create 5 OU's. One for each location. In each ou place the Computer Object in the OU. Using Group Policy Map the printer pending the computer. When the computer is booted it will map the printer before any user logs in. When the user logs in then the profile will also be in use. Just make sure you set Computer Configuration and not user configureation in GP.
 
This script will map your printers by location as long as your computers have location specific names.

Code:
Set Network = CreateObject("Wscript.Network") 
compname = network.computername
room = left(compname,3)
   
Select Case room
          Case "DP1"
        Network.AddWindowsPrinterConnection "\\server1\DP1Laser" 
        Network.SetDefaultPrinter "\\server1\DP1Laser" 

          Case "DP2"
        Network.AddWindowsPrinterConnection "\\server1\DP2Laser" 
        Network.SetDefaultPrinter "\\server1\DP2Laser" 


case else
 
End Select

Hope that helps.

I don't mean to sound bitter, cold, or cruel, but I am, so that's how it comes out - Bill Hicks
 
We used to do it baed on the 3rd octet of the ip address. The other suggestions posted here are probably better but in the logon script you can grab the ip address provided each location is identified by a different subnet. For example, miami 10.11.10.x ny 10.11.11.x boston 10.11.12.x you can grab the 3rd octet and write the correct printer to the profile. this is the poor mans way especially if you are using AD
 
Here is a sugeestion that will make use of the con2prt and the login script method you are already using:

1. Create a system variable on each PC called location, and set the value to whatever the physical location is.

2. Add something like this to your login script: If "%location%" == "mylocation" con2prt /c \\myserver\myprintersharename

Hope this helps.

 
I've used a few different ways over time and i really do feel that the VBscript way is the easiest lowest maintenance way as long as you have location specific machine names, or as loscajn says by IP.

I don't mean to sound bitter, cold, or cruel, but I am, so that's how it comes out - Bill Hicks
 
Agreed with bofhrevenge2- the VB Script stated is by far the easiest to implement and does the job perfectly.
 
I have been using > bofhrevenge2 < script for the past month and it is the best yet each new machine bang straight there !! sorry bof u cant have another star lol

It's the same each time with progress. First they ignore you, then they say you're mad, then dangerous, then there's a pause and then you can't find anyone who disagrees with you.
 
Sorry I have taken so long to reply guys... not had chance to get back to this.

Bof code looks great. Will give it a try and see the results. Will keep you posted.
 
The vbscript looks great! At one point I had tried this but ran into an issue where the script would freeze up if the printer was already mapped. Did anyone else run into this and is there a way around this?
 
run this snippet before mapping printers:

Code:
Set objNetwork = WScript.CreateObject("Wscript.Network")

For Each strPrinter In objNetwork.EnumPrinterConnections
	objNetwork.RemovePrinterConnection strPrinter, True, True
Next

Paul

Work on Windows, play on Linux.
 
Is there a way to get the VBScript to identify which OU the computer resides in and use that for a basis for printer mapping?

In my case I have a large single subnet and I have grouped my computers together in OU's representing portions of a building (ie. North, Northwest, West, Southwest, South, etc...)

PSC

Governments and corporations need people like you and me. We are samurai. The keyboard cowboys. And all those other people out there who have no idea what's going on are the cattle. Mooo! --Mr. The Plague, from the movie "Hackers
 
You might want to take a look at my FAQ on logon scripts. faq329-5798

I'll also be introducing a solution to this in the FAQ probably within the next 2 weeks if a new customer gives me the go ahead to do the work. So check back often, my solution will be a bit more straighforward than checking IP.

I hope you find this post helpful.

Regards,

Mark
 
In this particular instance parsing the IP address doesn't help me since all workstations are on the same subnet. I could use the computer name, but then I would have to extend the script by hundreds of lines.

I did consider using group membership of the computer account to deal with this, but then I realized that I would have to maintain both the location of computers in AD and their group memberships.

The reason that I ask is because I have users who come in and out of the building and need to map to the closest printer automatically on login.

I'll watch your script FAQ.

PSC

Governments and corporations need people like you and me. We are samurai. The keyboard cowboys. And all those other people out there who have no idea what's going on are the cattle. Mooo! --Mr. The Plague, from the movie "Hackers
 
I was in the exact same situation pscottc... what I did was to use con2prt in a log on script. I have already been to all workstations and setup a environment variable (COMPUTERLOCATION) and then in the log on script it checks the variable and then maps the nearest (pre-defined) printers.

**********************
CON2PRT /F
NET USE LPT2 /D
NET USE LPT3 /D
NET USE LPT4 /D

goto %COMPUTERLOCATION%

:West
CON2PRT /CD \\SERVER4\west4250N
net use lpt2 \\SERVER4\west4250N /Y
:East
CON2PRT /CD \\SERVER4\East4250N
net use lpt3 \\SERVER4\East4250N /Y
*******************

That is the way that I solved this.
 
A good suggestion mswilson16, but it won't work for this situation as the computers roam from site to site. So the assigned variable will point them to the wrong location when they roam.

I hope you find this post helpful.

Regards,

Mark
 
It's the users who roam from site to site. It is a reasonable solution, but is difficult to maintain. I would like to maintain the configured printers by OU location of the computer object.

What I think needs to happen is to parse the DN of the computer object in AD and then use a Case statement to determine which printers are assigned.

Something like:
Code:
Select Case strComputerOU
case "OU=Computers,OU=North,OU=Building40,DC=domain,DC=com"
WSHNetwork.AddWindowsPrinterConnection "\\Server\Printer1"

case "OU=Computers,OU=South,OU=Building40,DC=domain,DC=com"
WSHNetwork.AddWindowsPrinterConnection "\\Server\Printer2"

My problem is that I'm not really a programmer and I don't know how to acquire the DN for the computer account or parse it to remove the "CN=computername" portion.

Right now I'm looking at using groups to assign the printers. I would just assign the computers to groups. But I'm having trouble binding to the computer object to get the group membership.

PSC

Governments and corporations need people like you and me. We are samurai. The keyboard cowboys. And all those other people out there who have no idea what's going on are the cattle. Mooo! --Mr. The Plague, from the movie "Hackers
 
Here's the code I've been testing... excuse the mess, I've pulled code sements from several sources...

Basically it acquires the DN of the computer object in AD.

Code:
Option Explicit

ON ERROR RESUME NEXT

Dim WSHShell, WSHNetwork, objDomain, strDNSDomain
Dim UserString, UserObj, Path , strComputer, GroupObj
Dim objTrans, strNetBIOSDomain
Dim strUserDN, strComputerDN, objGroupList, objUser
Dim objComputer
Dim strHomeDrive, strHomeShare

' Constants for the NameTranslate object.
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1


Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")
Set objDomain = getObject("LDAP://rootDse")
strDNSDomain = objDomain.Get("defaultNamingContext")

' Use the NameTranslate object to find the NetBIOS domain name from the
' DNS domain name.
Set objTrans = CreateObject("NameTranslate")
objTrans.Init ADS_NAME_INITTYPE_GC, ""
objTrans.Set ADS_NAME_TYPE_1779, strDNSDomain
strNetBIOSDomain = objTrans.Get(ADS_NAME_TYPE_NT4)
WScript.Echo strNetBIOSDomain

' Use the NameTranslate object to convert the NT name of the computer to
' the Distinguished name required for the LDAP provider. Computer names
' must end with "$".
strComputer = WSHNetwork.computerName
objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & strComputer & "$"
strComputerDN = objTrans.Get(ADS_NAME_TYPE_1779)

WScript.Quit

PSC

Governments and corporations need people like you and me. We are samurai. The keyboard cowboys. And all those other people out there who have no idea what's going on are the cattle. Mooo! --Mr. The Plague, from the movie "Hackers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top