tech_boy Posted August 11, 2010 Share Posted August 11, 2010 Hi Guys,I've written a batch file that should delete all old printers on a computer, then import a 'ports.reg' registry file to add the correct IP ports to that machine, then it is meant to install the new printers.The problem is that after it has added the correct ports, it tries to add the new printers but I get the very helpful error message "Operation Could not be completed"....here is my script, and i've included the ports.reg file too:rem delete old printerswmic PRINTER deleterem stop printer spoolerNet stop Spoolerrem reg delete "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Ports" /f /va%windir%\regedit /S ports.regnet start spoolerpauserem add printerRUNDLL32 PRINTUI.DLL,PrintUIEntry /if /b "HP Officejet Pro K5400 Series" /f "\\juniorfs\NETLOGON\Printers\HP-K5400\hpwk540a.inf" /r "\\juniorfs\JSchoolVillach" /m "Villach Room"Ports.Reg:Windows Registry Editor Version 5.00[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Ports]"COM1:"="9600,n,8,1""COM2:"="9600,n,8,1""COM3:"="9600,n,8,1""COM4:"="9600,n,8,1""FILE:"="""LPT1:"="""LPT2:"="""LPT3:"=""@="""Ne00:"="""Ne01:"="""Ne02:"="""Ne03:"="""\\\\juniorfs\\JSchoolFL1"="""\\\\juniorfs\\JSchoolVillach"=""Any help would be gratefully received!Thanks a lot,-Jon Link to comment Share on other sites More sharing options...
Yzöwl Posted August 11, 2010 Share Posted August 11, 2010 I would think that the most likely problem is with your installation inf file.Likely problems:You cannot use a network path for /fThe network location specified in /f cannot be found.There is an error generated from the inf file.As far as the batch file goes, I'd personally prefer to see you keep everything in there instead of using a reg file merge, and possibly if using WMIC, sticking with it instead of using NET.EXE as well, e.g:@ECHO OFFREM Delete old printers except for Microsofts XPS Document PrinterWMIC PRINTER WHERE "PortName <> 'XPSPort:'" DELETEREM Stop printer spooler if startedWMIC SERVICE WHERE "Name='Spooler' AND State='Running'" CALL StopServiceREM Registry data changesSETLOCALSET "KEY=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Ports"REM Delete old registry dataREM REG DELETE "%KEY%" /VA /FREM Add new registry dataREG ADD "%KEY%" /VE /FREG ADD "%KEY%" /V COM1: /D "9600,n,8,1" /FREG ADD "%KEY%" /V COM2: /D "9600,n,8,1" /FREG ADD "%KEY%" /V COM3: /D "9600,n,8,1" /FREG ADD "%KEY%" /V COM4: /D "9600,n,8,1" /FREG ADD "%KEY%" /V FILE: /FREG ADD "%KEY%" /V LPT1: /FREG ADD "%KEY%" /V LPT2: /FREG ADD "%KEY%" /V LPT3: /FREG ADD "%KEY%" /V Ne00: /FREG ADD "%KEY%" /V Ne01: /FREG ADD "%KEY%" /V Ne02: /FREG ADD "%KEY%" /V Ne03: /FREG ADD "%KEY%" /V \\juniorfs\JSchoolFL1 /FREG ADD "%KEY%" /V \\juniorfs\JSchoolVillach /FENDLOCALREM Start printer spoolerWMIC SERVICE WHERE "Name='Spooler'" CALL StartServicePAUSE... Link to comment Share on other sites More sharing options...
FthrJACK Posted August 21, 2010 Share Posted August 21, 2010 (edited) CMD is a bit clunky for managing printers with imo...probably better if you switch to vbs.My machines are in OU's on AD, so say:SALES - salesprn1 - salesprn2 - salesprn3and so on. if a user logs onto a machine and its in the SALES\salesprn1\ OU on AD, then salesprn1 printer would be their default printer, i add the other printers in the same department as well just so they have the option of printing to another one if they choose. Users then get to move around and the nearest printer to them is always their default printer.'IMPORTANT. DO NOT user Share names to install printers. 'Use the full printer name as it appears on the servers printer menu.'Enter "none" into printers array to install no printers.'Do not leave array empty'IT COMPUTERSIf isMemberOu("OU=IT,OU=Admin workstations") Then printers = Array("\\GAM012\IT_COLOUR","\\GAM012\IT","\\GAM012\MARKS","\\GAM012\UNDERW2","\\GAM012\UNDERW3","\\GAM012\LOANS1","\\GAM012\LOANS2","\\GAM012\LOANS3","\\GAM012\FAXLESS1","\\GAM012\COLLECTIONS1","\\GAM012\COLLECTIONS2") defaultPrinter = "\\GAM012\IT" installPrinters = True 'LOANS1 COMPUTERSelseIf isMemberOu("OU=LOANS1,OU=Loans,OU=Workstations") Then printers = Array("\\CYC010\LOANS1","\\CYC010\LOANS2","\\CYC011\LOANS3","\\CYC010\FAXLESS1") defaultPrinter = "\\CYC010\LOANS1" installPrinters = True 'LOANS2 COMPUTERSelseIf isMemberOu("OU=LOANS2,OU=Loans,OU=Workstations") Then printers = Array("\\CYC010\LOANS1","\\CYC010\LOANS2","\\CYC011\LOANS3","\\CYC010\FAXLESS1") defaultPrinter = "\\CYC010\LOANS2" installPrinters = True 'ADMIN OFFICE COMPUTERSelseIf isMemberOu("OU=ADMIN,OU=Managerial,OU=workstations") Then printers = Array("\\GAM012\IT_COLOUR","\\GAM013\IT","\\CYC010\DALES","\\CYC010\MARKS") defaultPrinter = "\\CYC010\MARKS" installPrinters = True 'Define printers for specific machines ( we use if for laptops)ELSEIf isMemberOu("ou=laptops") Then ' get computer name Set WshNetwork = WScript.CreateObject("WScript.Network") strComputer = WshNetwork.ComputerName ' if computer name matches string then install some printers If lcase(strComputer) = lcase("laptop1") Then printers = Array("\\server\printer 1", "\\server\printer 2") defaultPrinter = "\\pabserv\Room 37" ' Define the default printer installPrinters = True ' Allows the install routines to run ElseIf lcase(strComputer) = lcase("laptop2") Then printers = Array("\\server\printer 1", "\\server\printer 2") defaultPrinter = "\\pabserv\Room 37" ' Define the default printer installPrinters = True ' Allows the install routines to run End IfEND IF' **** DO NOT EDIT BELOW THIS LINE ***On Error Resume Next IF installPrinters Then 'install printers Set objWSHNetwork = CreateObject("WScript.Network") Set WS_PRINTERS = objWSHNetwork.EnumPrinterConnections Set WshShell = WScript.CreateObject("WScript.Shell") FOR EACH printer in printers if LCase(printer) <> "none" Then objWSHNetwork.AddWindowsPrinterConnection(printer) END IF NEXT 'set Default Printer if LCase(defaultPrinter) <> "none" Then objWSHNetwork.SetDefaultPrinter defaultPrinter END IF Set WS_PRINTERS = Nothing Set WS_NET = Nothing Set WshShell = NothingEND IF' Determine OU Membership of computerPrivate Function isMemberOu(checkOu) Set objSysInfo = CreateObject("ADSystemInfo") strComputerDN = objSysInfo.ComputerName intIndexStart = InStr(LCase(strComputerDN), "ou=") intIndexLength = InStr(LCase(strComputerDN), ",dc=") - intIndexStart isMemberOu = false If intIndexStart > 0 Then compOu = LCase(Mid(strComputerDN, intIndexStart, intIndexLength)) End If If InStr(1, compOu, checkOu, 1) Then isMemberOu = true END IF Set objSysInfo = nothingEnd FunctionAs usual, theres probably a better way of doing it - but it works.I trimmed the script example down to make it easier to follow, obviously you would need to change it to suit your own AD structure and printer paths etc. Edited August 21, 2010 by FthrJACK Link to comment Share on other sites More sharing options...
cluberti Posted August 21, 2010 Share Posted August 21, 2010 Not to mention if you're using Vista or Win7 clients, printer management scripts are already built-in. Link to comment Share on other sites More sharing options...
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