NDPS Printer Installation Script
Novell Cool Solutions: Feature
By Ed Radke
Digg This -
Posted: 24 May 2007
This script was developed because, the site that I manage has 80 printers and it was not feasible to automatically install the printers to users as they move around too much. Eventually every printer would be installed to every desktop on campus. Not to mention, I very much dislike installing them via the Windows Explorer and Printer Wizards.
An easily configurable, menu driven utility, used to aid NDPS printer installation.
@echo off :: :: NDPSprn.cmd :: NDPS Printer Installer :: Written by Ed Radke :: :: This script is an easily configurable, menu driven utility, :: used to aid NDPS printer installation. :: :: This script was developed because, the site that I manage has 80 printers :: and it was not feasible to automatically install the printers to users :: as they move around too much and eventually every printer would be installed :: to every desktop on campus. :: Not to mention, I very much dislike installing them via the Windows Explorer :: and Printer Wizards. :: :: The 'CONTEXT' variable within this script, must be changed to refect the context :: in which the NDPS printers reside. And if applicable the 'NDSTREE' :: variable to reflect the NDS Tree in which the NDPS printers reside. :: :: The utility works by querying NDS via the Novell NLIST.EXE utility :: for objects of class 'NDPS PRINTER', filters and outputs the information, :: to be displayed to the user for selection. :: :: Except for the 'NLIST' utility, the script uses only uses commands that are native :: to Windows XP and should be stable as it employs several checks for validity of data, :: user input and temporary files. :: :: ** Variables ** :: :: NDSTREE = Novell Directory Services Tree name :: :: CONTEXT = Name context to which reflects the NDPS printer's location with leading dot (.OU.O) :: :: APPLYLONGNAMEFIX = Optionally, If set to '1', after installed, the printer is renamed :: from 'NDPSprinter.context' to 'NDPSprinter' :: Some legacy applications do not respond well to printers with names longer than 31 Characters. :: The context in the name can push the name beyond this limit. :: :: NLISTCMD = Blank by default, used to manually specify location of the NLIST utility :: if it does not reside in the PATH or F:\PUBLIC\ :: :: :: If anyone knows how to suppress the 'Connect to Printer' prompt, :: I'd appreciate the information! :: cls setlocal :: :: Set some variables :: set NDSTREE=TREE set CONTEXT=.OU.O set APPLYLONGNAMEFIX=1 set NLISTCMD= set TMPFILE1=%TEMP%\_ndps_1.tmp set TMPFILE2=%TEMP%\_ndps_2.tmp set TMPFILE3=%TEMP%\_ndps_3.tmp set COUNT=0 set PRNFOUND=0 call :CLEANUP echo Thankyou for choosing Edware (c) - %~n0 - Rev. 0.10.3 :: :: TEST FOR NLIST COMMAND :: if not "%NLISTCMD%"=="" ( if not exist "%NLISTCMD%" ( set ERR_DESC=The NLISTCMD variable is invalid! Correct or remove the value. goto :ABORT ) goto :FOUND ) NLIST / >NUL 2>&1 if not "%ERRORLEVEL%"=="9009" ( set NLISTCMD=NLIST.EXE goto :FOUND ) if exist F:\PUBLIC\NLIST.EXE ( set NLISTCMD=F:\PUBLIC\NLIST.EXE goto :FOUND ) :FOUND :: :: Query NDS :: echo Querying NDS for NDPS Printers... %NLISTCMD% "NDPS PRINTER" /C /CO %CONTEXT%>%TMPFILE1% if not exist %TMPFILE1% ( set ERR_DESC=File '%TMPFILE1%' does not exist , 'NLIST' command not available, or local file system problem. goto :ABORT ) :: :: Filter lines that do not have an NDPS printer object listed :: FIND /I " NDPS P" %TMPFILE1%>%TMPFILE2% if not exist %TMPFILE2% ( set ERR_DESC=Possible local file system problem. goto :ABORT ) :: :: Build the file that will become the menu :: echo Building Menu . . . ^<^< Please Wait ^>^> FOR /F "EOL=- TOKENS=1 DELIMS= " %%A IN (%TMPFILE2%) DO ( if not "%%A"=="" set PRNFOUND=1 call :BUILDMENU %%A ) if not "%PRNFOUND%"=="1" ( set ERR_DESC=No NDPS printers were found! goto :ABORT ) :UI :: :: Clear some repeating variables :: set SELECTIONS= set SELECTED= set SELECTOK= set NDPSPRINTER= set ERR_DESC= :: :: Display menu :: TYPE %TMPFILE3% :: :: Prompt user for input :: echo Make your selection(s) now or press enter alone to quit set /P SELECTIONS=Multiple selections separate with a space (i ii iii): :: :: Test for special options :: if "%SELECTIONS%"=="" ( goto :EOF ) :: :: Call 'INSTALL' lable passing 'space' delimited selections :: call :INSTALL %SELECTIONS% goto :EOF :INSTALL :: :: Parse menu file for the number selected and it's associated printer object :: set SELECTOK= set NDPSPRINTER= set SELECTED=%1 FOR /F "SKIP=4 TOKENS=1,2 DELIMS= " %%A IN (%TMPFILE3%) DO ( if "%%A"=="%SELECTED%" ( set SELECTOK=1 set NDPSPRINTER=%%B ) ) :: :: Validate selection :: if not "%SELECTOK%"=="1" ( set ERR_DESC='%SELECTED%', Invalid option! call :ERROR goto :SKIPSEL ) :: :: If by chance menu file is corrupt or for some other reason :: a printer name could not be set :: if "%NDPSPRINTER%"=="" ( set ERR_DESC=Coresponding printer name is missing for selection '%SELECTIONS%'. call :ERROR goto :SKIPSEL ) :: :: Execute command to install printer :: echo Installing Printer %SELECTED%, \\%NDSTREE%\%NDPSPRINTER%%CONTEXT% echo Click 'Yes' to complete installation. start /W RUNDLL32 PRINTUI.DLL,PrintUIEntry /q /in /j "Novell Distributed Print Services" /n \\%NDSTREE%\%NDPSPRINTER%%CONTEXT% if "%APPLYLONGNAMEFIX%"=="1" call :APPLYLONGNAMEFIX :: :: Test if another Selection is available :: :SKIPSEL if not "%2"=="" ( shift goto :INSTALL ) call :CLEANUP goto :EOF :: :: Build Menu :: :BUILDMENU if not exist %TMPFILE3% ( echo Select a printer by typing it's coresponding number>>%TMPFILE3% echo.>>%TMPFILE3% echo NUMBER PRINTER>>%TMPFILE3% echo ------ ------->>%TMPFILE3% ) set /A COUNT = COUNT + 1 echo %COUNT% %1>>%TMPFILE3% goto :EOF :APPLYLONGNAMEFIX :: :: Long name fix is applied :: echo Applying long printer name fix. start /W RUNDLL32 PRINTUI.DLL,PrintUIEntry /Xs /n "\\%NDSTREE%\%NDPSPRINTER%%CONTEXT%" printername "%NDPSPRINTER%" goto :EOF :CLEANUP :: :: Cleanup temp files :: if exist %TMPFILE1% del %TMPFILE1%>nul 2>&1 if exist %TMPFILE2% del %TMPFILE2%>nul 2>&1 if exist %TMPFILE3% del %TMPFILE3%>nul 2>&1 goto :EOF :: :: Script error conditions :: :ERROR echo %ERR_DESC% pause goto :EOF :ABORT echo ABORT ERROR OCCURED echo %ERR_DESC% pause goto :EOF
Except for the Novell 'NLIST' utility, the script uses only uses commands that are native to Windows XP
Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions. www.webwiseone.com