Printer Scripts

Sharing is caring!

<p>You can choose one of following script to use in login script<&sol;p>&NewLine;<p><b>Script1&colon;&nbsp&semi;<&sol;b><&sol;p>&NewLine;<pre><span>REM the &sol;q makes the command run quietly<&sol;span><br &sol;><br &sol;><span>REM Remember to replace &bsol;machineprinter with the path to your shared printer <&sol;span><br &sol;><br &sol;><span>REM Quietly install a network printer - per user<&sol;span><br &sol;><span>REM rundll32 printui&period;dll&comma;PrintUIEntry &sol;q &sol;in &sol;n "&bsol;machineprinter"<&sol;span><br &sol;><br &sol;><span>REM Quietly delete a named network printer - per user<&sol;span><br &sol;><span>REM rundll32 printui&period;dll&comma;PrintUIEntry &sol;q &sol;dn &sol;n "&bsol;machineprinte"<&sol;span><br &sol;><br &sol;><span>REM Set default printer<&sol;span><br &sol;><span>REM rundll32 printui&period;dll&comma;PrintUIEntry &sol;y &sol;n "&bsol;machineprinter"<&sol;span><br &sol;><br &sol;><span>REM Quietly install a network printer - per machine<&sol;span><br &sol;><span>REM rundll32 printui&period;dll PrintUIEntry &sol;q &sol;ga &sol;n "&bsol;machineprinter"<&sol;span><br &sol;><br &sol;><span>REM Quietly delete a network printer - per machine<&sol;span><br &sol;><span>REM rundll32 printui&period;dll PrintUIEntry &sol;q &sol;gd &sol;n "&bsol;machineprinter"<&sol;span><br &sol;><br &sol;><span>REM Quietly delete a specific printer driver<&sol;span><br &sol;><span>REM rundll32 printui&period;dll&comma;PrintUIEntry &sol;q &sol;dd &sol;m "PrinterDriver"<&sol;span><&sol;pre>&NewLine;<h4><span><b>Script2&colon;&nbsp&semi;<&sol;b><&sol;span><&sol;h4>&NewLine;<pre><span>'&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;<&sol;span><br &sol;><span>'&plus; Purpose&colon; This code will add a shared network printer<&sol;span><&sol;pre>&NewLine;<pre><span>'&plus;to your computer and set<&sol;span><br &sol;><span>'&plus; it to be the default printer<&sol;span><br &sol;><span>'&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;&plus;<&sol;span><br &sol;><span>' Variables must be declared<&sol;span><br &sol;><span>Option<&sol;span> <span>Explicit<&sol;span><br &sol;><span>' Suppress errors<&sol;span><br &sol;><span>on<&sol;span> <span>error<&sol;span> <span>resume<&sol;span> <span>next<&sol;span><br &sol;><span>' Declare Variables<&sol;span><br &sol;><span>Dim<&sol;span> <span>objPrinter<&sol;span><span>&comma;<&sol;span> <span>printerPath<&sol;span><br &sol;><span>' Path to printer &lpar;Add your information below&rpar;<&sol;span><br &sol;><span>printerPath<&sol;span> <span>&equals;<&sol;span> <span>"&bsol;yourserverprintername"<&sol;span> <br &sol;><span>Set<&sol;span> <span>objPrinter<&sol;span> <span>&equals;<&sol;span> <span>CreateObject<&sol;span><span>&lpar;<&sol;span><span>"WScript&period;Network"<&sol;span><span>&rpar;<&sol;span> <br &sol;><span>' Add printer<&sol;span><br &sol;><span>objPrinter<&sol;span><span>&period;<&sol;span><span>AddWindowsPrinterConnection<&sol;span> <span>printerPath<&sol;span><br &sol;><span>' Add as default<&sol;span><br &sol;><span>objPrinter<&sol;span><span>&period;<&sol;span><span>SetDefaultPrinter<&sol;span> <span>printerPath<&sol;span><br &sol;><span>wscript<&sol;span><span>&period;<&sol;span><span>sleep<&sol;span> <span>500<&sol;span><br &sol;><span>WScript<&sol;span><span>&period;<&sol;span><span>Quit<&sol;span><br &sol;><&sol;pre>&NewLine;<h4><span><b>&nbsp&semi;Script3&colon;<&sol;b><&sol;span><&sol;h4>&NewLine;<p><span><b>&nbsp&semi;<&sol;b><&sol;span><span style&equals;"font-family&colon; Courier&semi; font-size&colon; 10&period;0pt&semi; mso-ansi-language&colon; EN-GB&semi; mso-bidi-font-family&colon; Courier&semi;">Set WshNetwork &equals; CreateObject&lpar;&&num;8220&semi;WScript&period;Network&&num;8221&semi;&rpar;&nbsp&semi;<&sol;span><br &sol;><span style&equals;"font-family&colon; Courier&semi; font-size&colon; 10&period;0pt&semi; mso-ansi-language&colon; EN-GB&semi; mso-bidi-font-family&colon; Courier&semi;">PrinterPath &equals; &&num;8220&semi;&bsol;serverprintername&&num;8221&semi;&nbsp&semi;<&sol;span><br &sol;><span style&equals;"font-family&colon; Courier&semi; font-size&colon; 10&period;0pt&semi; mso-ansi-language&colon; EN-GB&semi; mso-bidi-font-family&colon; Courier&semi;">PrinterDriver &equals; &&num;8220&semi;HP LaserJet Whatever&&num;8221&semi;&nbsp&semi;<&sol;span><br &sol;><span style&equals;"font-family&colon; Courier&semi; font-size&colon; 10&period;0pt&semi; mso-ansi-language&colon; EN-GB&semi; mso-bidi-font-family&colon; Courier&semi;">WshNetwork&period;AddWindowsPrinterConnection PrinterPath&comma; PrinterDriver WshNetwork&period;SetDefaultPrinter &&num;8220&semi;&bsol;serverprintername<&sol;span><&sol;p>&NewLine;<p><span style&equals;"font-family&colon; Courier&semi; font-size&colon; 10&period;0pt&semi; mso-ansi-language&colon; EN-GB&semi; mso-bidi-font-family&colon; Courier&semi;">Note&colon;<&sol;span><br &sol;><span style&equals;"font-family&colon; Courier&semi; font-size&colon; 10&period;0pt&semi; mso-ansi-language&colon; EN-GB&semi; mso-bidi-font-family&colon; Courier&semi;">&lpar;<&sol;span><span style&equals;"font-family&colon; Courier&semi; font-size&colon; 10&period;0pt&semi; mso-ansi-language&colon; EN-GB&semi; mso-bidi-font-family&colon; Courier&semi;">Keep in mind this object is only used for connecting to network printers &lpar;or network shares&rpar;Save it as a VBS file&period;open ADUC and create OU&period;Go to the properties of that OU and click on the group policy tab&period; Click on NEW in the GP &comma;Go to user config&comma; windows settings&comma; scripts&comma; and double click on the LOGON&period; Add created VBS file&period;Run gpupdate &sol;force on the users box&period;&rpar;<&sol;span><&sol;p>&NewLine;

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.