RichB Posted May 7, 2010 Posted May 7, 2010 I have just started a new job as a network manager this week so trying to solve a few probelms. The network is a little dodgy to say the least they/we've (now) been having a problem for quite some time with printers dissappearing off the students pcs. We are using xp sp3, server 2003, there is a print server and the students use this very long scipt in there log on to select the printer, but nothing shows agter log in, this is not every pc just one in two!!! Any ideas? Cheers infact so long has to be on different posts On Error Resume Next Dim objShell, objFSO, msg, createfolder, strComputerName, objRegExp Dim RoomName, strDrive, strNetShare, strPrinterPath dim ppath, printers, wshnetwork 'Delete All Mapped Printers Before Mapping New Ones 'Remove all Network printers but not local printers Set WshNetwork = WScript.CreateObject("WScript.Network") Set Printers = WshNetwork.EnumPrinterConnections For i = 0 to Printers.Count - 1 Step 2 If Left(ucase(Printers.Item(i+1)),2) = "\\" Then WSHNetwork.RemovePrinterConnection Printers.Item(i+1) End IF Next set objShell = WScript.CreateObject("WScript.Shell") set objFSO = CreateObject("Scripting.FileSystemObject") set objNetwork = CreateObject("WScript.Network") set objRegExp = New RegExp set objPrinters = objNetwork.EnumPrinterConnections strComputerName = objNetwork.ComputerName 'Map room specific printers ' '-----Copy and adapt this section when assigning a printer------ ' 'If CheckRoom("ROOM-NAME-HERE") Then ' MapPrinter("NETWORK-PATH-TO-PRINTER-HERE") 'This line can be replicated multiple times for additional printers ' objNetwork.SetDefaultPrinter ("NETWORK PATH TO DEFAULT PRINTER HERE") 'End If ' '------------------------------------------------------------ If CheckRoom("ART_B17-01") Then MapPrinter("\\PENISTONE.shelley.local\B17_A4") MapPrinter("\\ART_B17-03\A3_1290") objNetwork.SetDefaultPrinter ("\\PENISTONE.shelley.local\B17_A4") End If If CheckRoom("ART_B17-02") Then MapPrinter("\\PENISTONE.shelley.local\B17_A4") MapPrinter("\\ART_B17-03\A3_1290") objNetwork.SetDefaultPrinter ("\\PENISTONE.shelley.local\B17_A4") End If If CheckRoom("ART_B17-04") Then MapPrinter("\\PENISTONE.shelley.local\B17_A4") MapPrinter("\\ART_B17-03\A3_1290") objNetwork.SetDefaultPrinter ("\\PENISTONE.shelley.local\B17_A4") End If If CheckRoom("ART_B17-TEACHER") Then MapPrinter("\\PENISTONE.shelley.local\B17_A4") MapPrinter("\\ART_B17-03\A3_1290") objNetwork.SetDefaultPrinter ("\\PENISTONE.shelley.local\B17_A4") End If If CheckRoom("ART_B17-03") Then MapPrinter("\\PENISTONE.shelley.local\B17_A4") objNetwork.SetDefaultPrinter ("\\PENISTONE.shelley.local\B17_A4") End If If CheckRoom("ART_B19-") Then MapPrinter("\\PENISTONE.shelley.local\B19_A4") MapPrinter("\\PENISTONE.shelley.local\B19_A3") objNetwork.SetDefaultPrinter ("\\PENISTONE.shelley.local\B19_A4") End If If CheckRoom("ART_B20-") Then MapPrinter("\\PENISTONE.shelley.local\B20_A4") MapPrinter("\\PENISTONE.shelley.local\B20_A3") objNetwork.SetDefaultPrinter ("\\PENISTONE.shelley.local\B20_A4") End If If CheckRoom("ART_B20A") Then MapPrinter("\\PENISTONE.shelley.local\B20A_A4") MapPrinter("\\PENISTONE.shelley.local\B20_A3") objNetwork.SetDefaultPrinter ("\\PENISTONE.shelley.local\B20A_A4") End If If CheckRoom("CAREERS-01") Then objNetwork.SetDefaultPrinter ("HP Deskjet F300 series") End If If CheckRoom("LSU-LAP5") Then MapPrinter("\\PENISTONE.shelley.local\SSC_FS4000DN") MapPrinter("\\PENISTONE.shelley.local\SSC_HP2600N") objNetwork.SetDefaultPrinter ("\\PENISTONE.shelley.local\SSC_FS4000DN") End If If CheckRoom("LAPTOP17-SSC2") Then MapPrinter("\\PENISTONE.shelley.local\SSC_FS4000DN") MapPrinter("\\PENISTONE.shelley.local\SSC_HP2600N") objNetwork.SetDefaultPrinter ("\\PENISTONE.shelley.local\SSC_FS4000DN") End If If CheckRoom("LAPTOP16-SSCMEE") Then MapPrinter("\\PENISTONE.shelley.local\SSC_FS4000DN") MapPrinter("\\PENISTONE.shelley.local\SSC_HP2600N") objNetwork.SetDefaultPrinter ("\\PENISTONE.shelley.local\SSC_FS4000DN") End If If CheckRoom("LAPTOP11-SSCTEA") Then MapPrinter("\\PENISTONE.shelley.local\SSC_FS4000DN") MapPrinter("\\PENISTONE.shelley.local\SSC_HP2600N") objNetwork.SetDefaultPrinter ("\\PENISTONE.shelley.local\SSC_FS4000DN") End If If CheckRoom("FYEAR-01") Then objNetwork.SetDefaultPrinter ("FYEAR_OLDHP") End If If CheckRoom("FYEAR-02") Then MapPrinter("\\FYEAR-01\FYEAR_OLDHP") objNetwork.SetDefaultPrinter ("\\FYEAR-01\FYEAR_OLDHP") End If If CheckRoom("D36") Then MapPrinter("\\PENISTONE.shelley.local\D36_FS4000DN") objNetwork.SetDefaultPrinter ("\\PENISTONE.shelley.local\D36_FS4000DN") End If If CheckRoom("HUM_") Then MapPrinter("\\PENISTONE.shelley.local\H77_FS4000DN") objNetwork.SetDefaultPrinter ("\\PENISTONE.shelley.local\H77_FS4000DN") End If If CheckRoom("B13") Then MapPrinter("\\PENISTONE.shelley.local\FT_A4Col") objNetwork.SetDefaultPrinter ("\\PENISTONE.shelley.local\FT_A4Col") End If If CheckRoom("B14") Then MapPrinter("\\PENISTONE.shelley.local\FT_A4Col") objNetwork.SetDefaultPrinter ("\\PENISTONE.shelley.local\FT_A4Col") End If If CheckRoom("B15") Then MapPrinter("\\PENISTONE.shelley.local\FT_A4Col") objNetwork.SetDefaultPrinter ("\\PENISTONE.shelley.local\FT_A4Col") End If If CheckRoom("DT_") Then MapPrinter("\\PENISTONE.shelley.local\DT_EPSON_C1100") objNetwork.SetDefaultPrinter ("\\PENISTONE.shelley.local\DT_EPSON_C1100") End If If CheckRoom("DT_B8-04") Then MapPrinter("DT_HP_A3") MapPrinter("\\PENISTONE.shelley.local\DT_EPSON_C1100") objNetwork.SetDefaultPrinter ("\\PENISTONE.shelley.local\DT_EPSON_C1100") End If If CheckRoom("LIBRARY") Then MapPrinter("\\PENISTONE.shelley.local\LIB_FS4000DN") objNetwork.SetDefaultPrinter ("\\PENISTONE.shelley.local\LIB_FS4000DN") End If If CheckRoom("C29") Then MapPrinter("\\PENISTONE.shelley.local\C29_7300DX") objNetwork.SetDefaultPrinter ("PDFCreator") End If If CheckRoom("G66") Then MapPrinter("\\PENISTONE.shelley.local\G65_FS4000DN") objNetwork.SetDefaultPrinter ("\\PENISTONE.shelley.local\G65_FS4000DN") End If If CheckRoom("ENG") Then MapPrinter("\\PENISTONE.shelley.local\G69_FS4000DN") objNetwork.SetDefaultPrinter ("\\PENISTONE.shelley.local\G69_FS4000DN") End If If CheckRoom("E43") Then MapPrinter("\\PENISTONE.shelley.local\E43_FS4000DN") objNetwork.SetDefaultPrinter ("\\PENISTONE.shelley.local\E43_FS4000DN") End If
RichB Posted May 7, 2010 Author Posted May 7, 2010 If CheckRoom("MATHS") Then MapPrinter("\\PENISTONE.shelley.local\MRA_FS4000DN") objNetwork.SetDefaultPrinter ("\\PENISTONE.shelley.local\MRA_FS4000DN") End If If CheckRoom("MUSIC") Then MapPrinter("\\PENISTONE.shelley.local\music_kyo") ' MapPrinter("\\PENISTONE.shelley.local\D36_FS4000DN") objNetwork.SetDefaultPrinter ("\\PENISTONE.shelley.local\music_kyo") End If ' I have put this here in case ICT Support Staff need to logon as a student If CheckRoom("ICTTEAM") Then MapPrinter("\\PENISTONE.shelley.local\ict_hpl7780") MapPrinter("\\PENISTONE.shelley.local\ict_hp5550") objNetwork.SetDefaultPrinter ("\\PENISTONE.shelley.local\ict_hpl7780") End If If CheckRoom("CLICKVIEW") Then MapPrinter("\\PENISTONE.shelley.local\ict_hpl7780") MapPrinter("\\PENISTONE.shelley.local\ict_hp5550") objNetwork.SetDefaultPrinter ("\\PENISTONE.shelley.local\ict_hpl7780") End If If CheckRoom("C31") Then MapPrinter("\\PENISTONE.shelley.local\C31_FS4000DN") objNetwork.SetDefaultPrinter ("\\PENISTONE.shelley.local\C31_FS4000DN") End If If CheckRoom("C30") Then MapPrinter("\\PENISTONE.shelley.local\C30_FS4000DN") objNetwork.SetDefaultPrinter ("\\PENISTONE.shelley.local\C30_FS4000DN") End If If CheckRoom("C25") Then MapPrinter("\\PENISTONE.shelley.local\C25_FS4000DN") objNetwork.SetDefaultPrinter ("\\PENISTONE.shelley.local\C25_FS4000DN") End If If CheckRoom("B22") Then MapPrinter("\\PENISTONE.shelley.local\B22_FS4000DN") objNetwork.SetDefaultPrinter ("\\PENISTONE.shelley.local\B22_FS4000DN") End If If CheckRoom("PE_ICT") Then MapPrinter("\\PENISTONE.shelley.local\PE_FS4000DN") objNetwork.SetDefaultPrinter ("\\PENISTONE.shelley.local\PE_FS4000DN") End If If CheckRoom("PE_P1") Then MapPrinter("\\PENISTONE.shelley.local\PE_FS4000DN") objNetwork.SetDefaultPrinter ("\\PENISTONE.shelley.local\PE_FS4000DN") End If If CheckRoom("MFL") Then MapPrinter("\\PENISTONE.shelley.local\MFL_FS4000DN") objNetwork.SetDefaultPrinter ("\\PENISTONE.shelley.local\MFL_FS4000DN") End If If CheckRoom("H77") Then MapPrinter("\\PENISTONE.shelley.local\H77_FS4000DN") objNetwork.SetDefaultPrinter ("\\PENISTONE.shelley.local\H77_FS4000DN") End If If CheckRoom("H72") Then MapPrinter("\\PENISTONE.shelley.local\H77_FS4000DN") objNetwork.SetDefaultPrinter ("\\PENISTONE.shelley.local\H77_FS4000DN") End If If CheckRoom("G67") Then MapPrinter("\\PENISTONE.shelley.local\G67_FS4000DN") objNetwork.SetDefaultPrinter ("\\PENISTONE.shelley.local\G67_FS4000DN") End If If CheckRoom("G68") Then MapPrinter("\\PENISTONE.shelley.local\G67_FS4000DN") objNetwork.SetDefaultPrinter ("\\PENISTONE.shelley.local\G67_FS4000DN") End If If CheckRoom("G65") Then MapPrinter("\\PENISTONE.shelley.local\G65_FS4000DN") objNetwork.SetDefaultPrinter ("\\PENISTONE.shelley.local\G65_FS4000DN") End If If CheckRoom("SCI_A") Then MapPrinter("\\PENISTONE.shelley.local\SCI_RES") objNetwork.SetDefaultPrinter ("\\PENISTONE.shelley.local\SCI_RES") End If If CheckRoom("SCI_E") Then MapPrinter("\\PENISTONE.shelley.local\MLAB_FS2000") objNetwork.SetDefaultPrinter ("\\PENISTONE.shelley.local\MLAB_FS2000") End If If CheckRoom("SFC") Then MapPrinter("\\PENISTONE.shelley.local\SFC_HP_P2015") objNetwork.SetDefaultPrinter ("\\PENISTONE.shelley.local\SFC_HP_P2015") End If If CheckRoom("STUDENTSUPP") Then MapPrinter("\\PENISTONE.shelley.local\SSC_FS4000DN") MapPrinter("\\PENISTONE.shelley.local\SSC_HP2600N") objNetwork.SetDefaultPrinter ("\\PENISTONE.shelley.local\SSC_FS4000DN") End If If CheckRoom("STAFFQRM") Then MapPrinter("\\PENISTONE.shelley.local\SQR_FS4000DN") objNetwork.SetDefaultPrinter ("\\PENISTONE.shelley.local\SQR_FS4000DN") End If If CheckRoom("MOBILE-") Then MapPrinter("\\PENISTONE.shelley.local\MOBILES") objNetwork.SetDefaultPrinter ("\\PENISTONE.shelley.local\MOBILES") End If Function MapPrinter(strPrinterPath) PrinterPath = strPrinterPath objNetwork.AddWindowsPrinterConnection PrinterPath End Function Function CheckRoom(RoomName) CheckRoom = False objRegExp.IgnoreCase = True objRegExp.Global = True objRegExp.Pattern = RoomName CheckRoom = objRegExp.Test(strComputerName) End Function set objShell = NOTHING set objFSO = NOTHING set objNetwork = NOTHING
danrhodes Posted May 7, 2010 Posted May 7, 2010 Good but too bl**dy complicated for me! Just keep it simple and it will work fine. You can run this remotely and it will add a permenant connection to the specified printer for who ever loggs on, wether pupil or staff. RUNDLL32 PRINTUI.DLL,PrintUIEntry /c \\MachineName1 /ga /n "\\ServerName\PrinterShare" RUNDLL32 PRINTUI.DLL,PrintUIEntry /c \\MachineName2 /ga /n "\\ServerName\PrinterShare" RUNDLL32 PRINTUI.DLL,PrintUIEntry /c \\MachineName3 /ga /n "\\ServerName\PrinterShare" RUNDLL32 PRINTUI.DLL,PrintUIEntry /c \\MachineName4 /ga /n "\\ServerName\PrinterShare" Or you can run it locally. RUNDLL32 PRINTUI.DLL,PrintUIEntry /ga /n "\\ServerName\PrinterShare" D 1
RichB Posted May 10, 2010 Author Posted May 10, 2010 Im taking it I would put the script in a .bat file then place it in the start up?
RichB Posted May 10, 2010 Author Posted May 10, 2010 Anyone else have any ideas? I've got about 50% of the printers down.....
SYNACK Posted May 10, 2010 Posted May 10, 2010 Does the problem persist on the samcomputers for every logon or is it just once in a while that this happens? You could simplify the above script and still keep all of its functionallity by combining some of the room checks as their printer allocation is the same i.e. If ( CheckRoom("ART_B17-02") OR CheckRoom("ART_B17-02") OR CheckRoom("ART_B17-02") OR CheckRoom("ART_B17-TEACHER") ) Then MapPrinter("\\PENISTONE.shelley.local\B17_A4") MapPrinter("\\ART_B17-03\A3_1290") objNetwork.SetDefaultPrinter ("\\PENISTONE.shelley.local\B17_A4") End If This would shrink it substantally from a reading and debugging point of view. Secondly I would be tempted to comment out: On Error Resume Next to 'On Error Resume Next which would allow any error messages that happened to show up so that you could look to them for clues. Just to check your print server is running a Windows Server OS rather than XP as XP has a nasty 10 connection limit. 1
RichB Posted May 10, 2010 Author Posted May 10, 2010 It is a windows server OS, very new to this vbs scripting stuff was using shared printers before and for some reason it will not allow it on this network. Just looking for a work around until half term when I can rip everything apart a simple script to manually change and add printers per room. Will try the above Thanks
danrhodes Posted May 10, 2010 Posted May 10, 2010 Im taking it I would put the script in a .bat file then place it in the start up? No you do not need to put the script into the startup script it only needs to be ran once. I usually use Excel to concatenate the names of the machines into a script, copy into notepad and then run it with the machines turned on. Once the script has ran the printers will be permenantly added to the machine until they are removed using the same script but with the /gd switch in place of the /ga switch. D
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