projector1 Posted April 5, 2007 Author Posted April 5, 2007 all our machines are setup as room name followed by pc number ie R21-2 R2-1 the script provided by this site has worked fine. I have just reghosted batch of student laptops. The only issue is that the names are LAPTOP followed by the year purchased followed by department followed by the machine number ie LAPTOP05H01 Unfortunatelly these do match the naming convention we have implemented. i have tried adding these to the vbscript but they are not mapping the printer. I have tried this (extracted from the script) ' Add printer connections dependant upon location Select Case (Right(computerName, 7)) Case "OP05H??" WshNetwork.AddWindowsPrinterConnection "\\cse2k01\historylaser" WshNetwork.SetDefaultPrinter "\\cse2k01\historylaser" I also tried it as "OP05H*" this did not work is it possible to use wildcards in vbscripts? (all xp pro sp2 clients)
krisd32 Posted April 5, 2007 Posted April 5, 2007 2003 server r2 does this for me, and works very well infact! apart from theat you can't set default printers with it but i got around that problem. Kris
Ric_ Posted April 5, 2007 Posted April 5, 2007 You could use Mid(computerName, 7, 5) This will return 5 characters from the computer name, starting at the 7th character.
projector1 Posted April 5, 2007 Author Posted April 5, 2007 thanks ric i will try that after i enjoy these few days off! phew! roll on july ( 3 week trip to india)
Heebeejeebee Posted April 6, 2007 Posted April 6, 2007 As bossman says, it's this easy. Off topic but how did you create that example? That's the sort of thing I need to do for some of our staff but the software I've managed to find is clunky and doesn't make smooth animations. Now back to topic. We tried R2's push printers features and had to go back to a script that picks up the room names because the printers were not always being installed with R2 (see this thread) HBJB
Heebeejeebee Posted April 6, 2007 Posted April 6, 2007 HBJB: I used Wink. I'm checking it out now. Edit: Looks nice and does the job well. Free as well! Thanks HBJB
meastaugh1 Posted April 6, 2007 Posted April 6, 2007 HBJB: I used Wink. Thanks for the tip, very useful.
srochford Posted April 10, 2007 Posted April 10, 2007 @joedetic Yeah ...the problem with monolithic batch files is that the Windows command processor doesn't do string splicing. This means you either have to name each printer or put the room attribute in an enviromental variable. Not completely true. NT/2000/XP do string slicing and splicing. It's a bit hard work but it's all possible - try this: @echo off set a=123456789 set b=%a:~0,3% set c=%a:~3,2% set d=%c%%b% echo %a% echo %b% echo %c% echo %d% Of course room identifiers don't matter so much if the script is run from a GPO which then selects the right computers. For those prefering the centralisation of monolithic scripts it's better to use a grown up language such as VBS/JScript or KiXtart Agreed to the last bit :-) all you then have to worry about is putting the computers in the right OU and the job's all done.
projector1 Posted April 11, 2007 Author Posted April 11, 2007 You could use Mid(computerName, 7, 5) This will return 5 characters from the computer name, starting at the 7th character. well back at work today was just mooching over your suggestion...... if i use Mid(computerName, 7, 5) that will not work with the rooms that have pc's named R30-13 need to extract R30- RDCXP21 need to extract RDC or RDCXP
srochford Posted April 11, 2007 Posted April 11, 2007 This is where you need a standard naming convention that helps with things like this. for example, in theory all our room names are like WG150 (Willesden; G Block; 1st floor; room 50) so we should be able to name computers and know that the first 5 characters are the room number. This all falls over when you get rooms like WFG33A (room 33A on the ground floor) We've now given up trying to assume we can have a standard PC name and put machines in OUs - it's easy to find the OU name and that effectively is the room name. If you decide to rename a batch of computers then it can (of course!) be scripted - I've put some info here:http://techinfo.cnwl.ac.uk/Windows%20Scripts/default.asp?dest=Rename%20a%20remote%20computer.htm
mac_shinobi Posted April 11, 2007 Posted April 11, 2007 You could use Mid(computerName, 7, 5) This will return 5 characters from the computer name, starting at the 7th character. well back at work today was just mooching over your suggestion...... if i use Mid(computerName, 7, 5) that will not work with the rooms that have pc's named R30-13 need to extract R30- RDCXP21 need to extract RDC or RDCXP I think you will find that the split function will do the trick for you if you have hyphens in your room names ie RDC-# then you can split it using the hyphen which is the common denominator
projector1 Posted April 12, 2007 Author Posted April 12, 2007 sorry over the summer i plan to standardise the it suite naming convention not all the pc names contain hyphens i have contemplated another ou for laptops thus another vb script, but if there is away around it then i would be greatful thanks for the suggestion though
beeswax Posted April 12, 2007 Posted April 12, 2007 As bossman says, it's this easy. no replay button?
webman Posted April 12, 2007 Posted April 12, 2007 As bossman says, it's this easy. no replay button? Just F5
Joedetic Posted April 12, 2007 Posted April 12, 2007 @NetworkGeezer. Yeah, the batch files did require environment variables and was an extremely poor bodge that was used by the person that designed and built the network the first time round. It got a complete rebuild on an external contract because it was so poorly designed. The VB script i referred to was the logon script that did EVERYTHING. The "super logon script" i think it was called or something like that (one of the techies wrote it). It checked the machine name and then assigned printers based on that IIRC. It's been a year since i was still helping out in ICT services and there were a few months before i left where i was focusing on my education so i could get into uni so it's a long time since i had anything to do with it to be honest.
Andi Posted April 17, 2007 Posted April 17, 2007 We connect our printers with a VBScript using con2prnt.exe which is then assigned per OU with GPO. This works a treat for our client stations, however. It doesn't work for our terminal stations. Our terminal stations connect using thinstation which boots from PXE on the network cards. This requires them to have an account in AD on which you set the Remote Install properties to use the thinstation boot file. What I want to be able to do is to assign a printer to the terminal station depending on which classroom it is. Of course the terminal stations do not take any notice of GPO despite the fact that they are placed in OUs with them set. Currently they all connect to one terminal server which has all the necessary printers installed which then relies on the student choosing the correct printer from the drop down list, which of course never happens. Does anybody know a way to sort this?
ChrisH Posted April 17, 2007 Posted April 17, 2007 Look at the scripts in the scripts section. Ric's in particular. You can do it using the clientname. He has had thinstation running and assigning printers according to their name with no problem once you get the client name and not comptername as that returns the terminal servers name.
projector1 Posted April 20, 2007 Author Posted April 20, 2007 ok thanks i will do that this weekend after i start and finish the dreaded tiling on the bathroom at home
mac_shinobi Posted April 20, 2007 Posted April 20, 2007 Just out of curiousty where is RIC's post and how did you get the client name versus the machine name ?
Ric_ Posted April 20, 2007 Posted April 20, 2007 Check out http://edugeek.net/index.php?name=Forums&file=viewtopic&t=404 The important bit is LCase(WshShell.ExpandEnvironmentStrings("%CLIENTNAME%")) The system has two variables on thin clients: * computername = the server's name * clientname = the client machine's name Hope this helps.
accura2000 Posted April 27, 2007 Posted April 27, 2007 I currently use con2prt.exe to assign printers to computers based on location. Just enter a location into the enviornment settings in windows and make yourself a logon script and hey presto. Work flawlessly for the last 18 months.
Rozzer Posted April 27, 2007 Posted April 27, 2007 Here is a printer script which can be done by room and has been very easy to run. It was provided by our network migration. Processprinter.vbs Option Explicit DIM ForReading DIM ForWriting DIM ForAppending DIM strComputer DIM WshNetwork DIM objWMIService DIM colInstalledPrinters DIM objPrinter DIM FileIn DIM FSO DIM WshShell DIM objEnv DIM ClientName DIM Username DIM objFile DIM Found DIM Wild DIM strContents DIM SpltInput DIM Col0 DIM COl1 DIM ColLen DIM UFound DIM UMatch DIM Match DIM objShell DIM FN_Loop ForReading = 1 ForWriting = 2 ForAppending = 8 strComputer = "." Set WshNetwork = CreateObject("WScript.Network") Set objShell = CreateObject("WScript.Shell") Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colInstalledPrinters = objWMIService.ExecQuery ("Select * from Win32_Printer") ON ERROR RESUME NEXT REM Delete all printers except for local ones. For Each objPrinter in colInstalledPrinters If Left(objPrinter.Name,2) = "\\" Then objPrinter.Delete_ End If Next ON ERROR GOTO 0 FileIn = "\\clustaps\batch$\ClientPrinterMapping.txt" Set FSO = CreateObject("Scripting.FileSystemObject") Set WshShell = WScript.CreateObject("WScript.Shell") Set objEnv = WshShell.Environment("Process") FOR FN_Loop = 1 TO 5 Set WshShell = WScript.CreateObject("WScript.Shell") ClientName = objEnv("COMPUTERNAME") IF ClientName <> "" THEN EXIT FOR Wscript.Sleep(5000) IF FN_LOOP = 5 THEN MSGBOX "Unable to read the computer name , please inform a technician." END IF NEXT Username = objEnv("USERNAME") Set objFile = FSO.OpenTextFile(FileIn, ForReading) Found = 0 Wild = 1 Do While Not objFile.AtEndOfStream strContents = objFile.ReadLine SpltInput = split(strContents,VBTAB) If ubound(SpltInput) > 0 Then Col0 = SpltInput(0) Col1 = SpltInput(1) If UCase(Col0) = "NAME" THEN ColLen = InStr(Col1,"*") If Found = 0 and Wild = 1 Then IF COlLen > 0 Then IF UCASE(Left(ClientName, ColLen -1)) = UCASE(Left(Col1, ColLen -1)) THEN Found = 1 Wild = 1 Match = Col1 End IF End If End If IF ColLen = 0 Then IF UCase(ClientNAme) = UCase(Col1) THEN Found = 1 Wild = 0 Match = Col1 End If End If End If IF UCASE(Col0) = "UNAME" THEN IF UCase(Username) = UCase(Col1) THEN UFound = 1 UMatch = Col1 End If End IF End If Loop objFile.close IF Found = 1 Then call Readblock("NAME",Match) END IF IF UFound = 1 Then call Readblock("UNAME",Username) END IF sub ReadBlock(Match1,Match2) Set objFile = FSO.OpenTextFile(FileIn, ForReading) Do While Not objFile.AtEndOfStream strContents = objFile.ReadLine SpltInput = split(strContents,VBTAB) If ubound(SpltInput) > 0 Then Col0 = SpltInput(0) Col1 = SpltInput(1) If UCASE(Col0) = UCASE(Match1) AND UCASE(Col1) = UCASE(Match2) Then Do While Not objFile.AtEndOfStream strContents = objFile.ReadLine SpltInput = split(strContents,VBTAB) If ubound(SpltInput) > 0 Then Col0 = SpltInput(0) Col1 = SpltInput(1) IF UCASE(Col0) = "MAP" Then ON ERROR RESUME NEXT FOR FN_Loop = 1 TO 5 WshNetwork.AddWindowsPrinterConnection Col1 IF Err.Number = 0 THEN EXIT FOR Wscript.Sleep(5000) IF FN_LOOP = 5 THEN MSGBOX "Unable to map the printer " + Col1 + ", please inform a technician." END IF NEXT ON ERROR GOTO 0 End If If UCASE(Col0) = "DEFAULT" Then ON ERROR RESUME NEXT FOR FN_Loop = 1 TO 5 WshNetwork.SetDefaultPrinter Col1 IF Err.Number = 0 THEN EXIT FOR Wscript.Sleep(5000) IF FN_LOOP = 5 THEN MSGBOX "Unable to set the default printer to " + Col1 + ", please inform a technician." END IF NEXT ON ERROR GOTO 0 End If If UCASE(Col0) = "NAME" OR UCASE(Col0) = "UNAME" Then Exit Do End If End If Loop EXit Do End If End If Loop objFile.close End sub You have this VBS file to run on each log in. You then make a txt file which will contain the following. This is a example. ClientPrinterMapping.txt REM Room B11 NAME B11* MAP \\apsrv01\B11_BW_HP4100 MAP \\apsrv01\B11_Colour_TallyT8006e DEFAULT \\apsrv01\B11_Colour_TallyT8006e REM Room B12 NAME B12* MAP \\apsrv01\B12_BW_HP4100 MAP \\apsrv01\B12_Colour_TallyT8006e DEFAULT \\apsrv01\B12_BW_HP4100 REM B13 NAME B13* MAP \\apsrv01\B13_BW_HP4050 MAP \\apsrv01\B13_Colour_TallyT8006e DEFAULT \\apsrv01\B13_BW_HP4050 Its very easy and i have never had to touch the VBS file only the txt file. Sorry for the long post. Ross
srochford Posted April 27, 2007 Posted April 27, 2007 Just enter a location into the enviornment settings in windows and make yourself a logon script and hey presto. I always love the "just enter a ..." type things :-) These are always the bits which get forgotten (because it's one extra thing to do) :-)
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now