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 Mike Lewis 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
 
OK, so you are sayign ONLY the users move and they don't take laptops with them?

I hope you find this post helpful.

Regards,

Mark
 
The users move around, yes. Most of the workstations are regular computers. Users with laptops generally have the laptop so they can work at home, not move from office to office. If a user does take a laptop to another office, there are specific locations where they can dock. Each location is on a unique subnet. On the other hand the regular computers may be in the same subnet but different parts of a larger building.

This is how the printer portion of the logon script should go...

1) Determine OU of computer
2) If computer is in laptop OU, map printers based on IP subnet
3) If computer is in other OU, map printers based on OU


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
 
Would something like this help you? This will check the Workstation's name and base the location on the name. Hope this helps.

set net = CreateObject("WScript.Network")
workstation=net.computername
location=left(workstation,2)
printername=""
Select case location
case "L1" printername="L1 LaserJet"
case "L2" printername="L2 LaserJet"
case "L3" printername="L3 LaserJet"
End Select
if printername<>"" then net.SetDefaultPrinter(printername)
set net = Nothing



 
I know I should be using VBS for my logon scripts but at the moment I am still using BAT files. Like mswilson16 I have created a user defined environment variable on each workstation called "SITEID". In the user properties in AD Users and Computers the logon script is defined as %siteid%.bat. When users move between sites they pick up either north.bat or west.bat depending on the computer they are using.

To set the default printer (and to connect to new printers if required) I use:

rundll32 printui.dll,PrintUIEntry /in /n \\server\printername
rundll32 printui.dll,PrintUIEntry /in /n \\server\nextprintername /y

For notebook users it isn't perfect but a shortcut on the desktop to run the appropriate logon script gets around the problem.

Changing the environment variable is easier than changing the workstation name in my experience.

The above conclusions have been reached through much help from the helpful people on Tek-Tips.
 
In that case you could use vbscript and set the location to those specific batch files (%siteid%) within the vbscript.
 
bofhrevenge2 - I like your script. I am a novice to vbs so i hope you don't mind if i ask the following. Basically, could you tell me (or highlight) the syntax in the script that I would have to change for my settings - in other words highlight the difference between the generic syntax and the example syntax (eg computer or printer name).For example in your script 'room = left(compname,3)' - is that generic or do i change it to my name(s). I'm really sorry if this all sounds trivial, it's just that i'm new to vbs and your printer script will sort my problem out.
thanks, try and have a good day.
 
Here's the script that I built... Let me know if you see any problems with the thought process or methodology.

Code:
[COLOR=green]'==========================================================================
'
' NAME: Printer Mapping by OU (insert for logon.vbs)
'
' AUTHOR: Paul S. Chapman, Halcyon Dreams
' URL: [URL unfurl="true"]http://www.halcyondreams.com[/URL]
' DATE  : 6-6-2005
'
' COMMENT: 
' 	Thanks to Richard L. Mueller ([URL unfurl="true"]www.rlmueller.net)[/URL] And
'	Mark D. MacLachlan ([URL unfurl="true"]www.thespidersparlor.com)[/URL] for code segments And
'	ideas to build this script.
'
'==========================================================================[/color]

Option Explicit

ON ERROR RESUME NEXT

Dim objShell, objNetwork, objDomain, objTrans, objWMI, objNIC
Dim strComputerDN, strComputerOU, strNum, strSubnet
Dim arrSplitDN, arrSplitIP

[COLOR=green]' Constants for the NameTranslate object.[/color]
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1

Set objShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")
Set objDomain = getObject("LDAP://rootDse")
Set strComputerOU = Nothing

[COLOR=green]' 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 "$". [/color]
Set objTrans = CreateObject("NameTranslate")
objTrans.Set ADS_NAME_INITTYPE_GC, ""
objTrans.Set ADS_NAME_TYPE_NT4, objNetwork.UserDomain & "\" _
& objNetwork.computerName & "$"
strComputerDN = objTrans.Get(ADS_NAME_TYPE_1779)
'WScript.Echo strComputerDN

[COLOR=green]' Split the DN on the comma delimeter[/color]
arrSplitDN = Split(strComputerDN, ",")

[COLOR=green]' Determine where computer is in AD.  If computer account is in computers,
' then error and quit.  If computer is a laptop determine IP subnet.[/color]
If UCase(arrSplitDN(1)) = "CN=COMPUTERS" Then
	WScript.Echo "Computer is in Computers Container.  No printers" _
	& " assigned.  Contact your administrator."
	WScript.Quit

Elseif UCase(arrSplitDN(1)) = "OU=LAPTOPS" Then
	Set objWMI = GetObject("winmgmts:\\.\root\cimv2")
	Set objNIC = objWMI.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True")
	
	For Each strNum in objNIC
		arrSplitIP = Split(strNum.IPAddress(0),".")
	Next
	
	strSubnet = arrSplitIP(0) & "." & arrSplitIP(1) & "." & arrSplitIP(2) & ".0"
	
Else
	[COLOR=green]'Combine OU entries back into one entry delimeted with comma.[/color]
	For strNum = 0 To UBound(arrSplitDN)
		If Left(arrSplitDN(strNum),3) = "OU=" Then
			If strComputerOU = "" Then
				strComputerOU = arrSplitDN(strNum)
			Else
				strComputerOU = strComputerOU & "," & arrSplitDN(strNum)
			End If
		End If
	Next
End If
'WScript.Echo strComputerOU

strComputerOU = UCase(strComputerOU)
[COLOR=green]'Assign printers based on OU membership[/color]
Select Case strComputerOU
	Case "OU=COMPUTERS,OU=NORTH,OU=BUILDING40"
		objNetwork.AddWindowsPrinterConnection "\\Server\Printer1"
		
	Case "OU=COMPUTERS,OU=SOUTH,OU=BUILDING40"
		WSHNetwork.AddWindowsPrinterConnection "\\Server\Printer2"
	
End Select

[COLOR=green]'Assign printers to laptop users[/color]
Select Case strSubnet
	Case "192.168.1.0"
		WSHNetwork.AddWindowsPrinterConnection "\\Server\Printer1"
		
	Case "192.168.2.0"
		WSHNetwork.AddWindowsPrinterConnection "\\Server2\Printer1"
		
End Select

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
 
Bofh's script looks simple but effective the "room = left(compname,3)" looks up the PC's name then takes the first 3 letters to work out where the PC is located then adds the correct printer.

All PC's need to have a location specific name. (Well the first 3 characters anyway)

E.G. If you had a room or office called IT1 and one call IT2 you could call your PC's IT1_001 through IT1_whatever and IT2_001 through whatever. Then the next bit of the script adds the correct printer E.G. IT1Laser which would be in the appropriate room (office).
 
That suggests that you're willing to go around and rename all of your workstations if you don't currently have a hierarchical enterprise naming convention.

I'm proposing a purely dynamic and administrative way to control printer assignments. If you drag and drop 100 workstations from one OU to another, users will get new printer assignments on the next logon.

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
 
PScottC your script looks excellent but the name schooltechnical indicates a high school which is likely to be a small location with location specific PC names so i was thinking Bofh's script look user friendly for a VB learner while still remaining effective.
 
FYI, I've begun writing a new FAQ that I know will address your issue. I just need another day or two and I can provide you with a better solution.

I hope you find this post helpful.

Regards,

Mark
 
hi, all of this is really helpful. But i'm just wondering if anybody can answer my initial query. I know it sounds really trivial but i am new to vbs scripting: can somebody mark out or highlight the default syntax in the bofhrevenge2 script, and then what i would have to change for my own settings (server or printer name for example).In other words highlight the difference between the generic syntax and the example syntax (eg computer or printer name)
sorry to keep being a pain
try and have a good day everyone
 
Code:
Set Network = CreateObject("Wscript.Network") 
compname = network.computername
room = left(compname,3)
   
Select Case room
          Case "[red]DP1[/red]"
        Network.AddWindowsPrinterConnection "[red]\\server1\DP1Laser[/red]" 
        Network.SetDefaultPrinter "[red]\\server1\DP1Laser[/red]" 

          Case "[red]DP2[/red]"
        Network.AddWindowsPrinterConnection "[red]\\server1\DP2Laser[/red]" 
        Network.SetDefaultPrinter "[red]\\server1\DP2Laser[/red]" 


case else
 
End Select

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
 
OK, finally had a spare moment to work on the FAQ. Not sure how long it will take for this link to be public. faq329-5908



I hope you find this post helpful.

Regards,

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top