{"id":392,"date":"2011-10-27T20:45:49","date_gmt":"2011-10-27T20:45:49","guid":{"rendered":"http:\/\/giraffeit.com\/?p=392"},"modified":"2011-10-27T20:45:49","modified_gmt":"2011-10-27T20:45:49","slug":"printer-scripts-for-windows-seven","status":"publish","type":"post","link":"https:\/\/giraffeit.com\/index.php\/2011\/10\/27\/printer-scripts-for-windows-seven\/","title":{"rendered":"Printer Scripts for Windows Seven"},"content":{"rendered":"<p>I have been onto a site recently, and had issues with the Group Policy Preferences not applying to the printers. I found out that this was due to the time it takes the printer to respond to the request to be &#8220;mapped&#8221; and made default.<\/p>\n<p>I spent a few hours and hacked around some code and came up with this little masterpiece to allow multiple room printers to be added to the relevant OU based PC<\/p>\n<p>&#8216;&#8212;&#8212;&#8212;&#8212;&#8212;Delete all Printers&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nDim wshNetwork, sPrintPath, clPrinters, i<br \/>\nSet wshNetwork = CreateObject(&#8220;WScript.Network&#8221;)<\/p>\n<p>&#8216;Remove Existing Printers<br \/>\nSet clPrinters = wshNetwork.EnumPrinterConnections<br \/>\nOn Error Resume Next<br \/>\nFor i = 0 to clPrinters.Count &#8211; 1 Step 2<br \/>\nwshNetwork.RemovePrinterConnection clPrinters.Item(i+1), true<br \/>\nNext<br \/>\nOn Error Goto 0<\/p>\n<p>&#8216;&#8212;- For citrix script, un-comment following two lines:<\/p>\n<p>&#8216;Set Sh = CreateObject(&#8220;WScript.Shell&#8221;)<br \/>\n&#8216;sys = Sh.ExpandEnvironmentStrings(&#8220;%CLIENTNAME%&#8221;) &#8216;sys= the returned workstation name (Citrix only)<\/p>\n<p>&#8216;&#8212;- For normal Windows machines un-comment the following line<\/p>\n<p>sys = wshNetwork.ComputerName &#8216;sys = computer name (standard domain workstations &#8211; not citrix)<\/p>\n<p>&#8216;&#8212;- Note, you can&#8217;t have both of these uncommented!!!<\/p>\n<p>&#8216;User = CreateObject(&#8220;WScript.Network&#8221;).Username &#8216; This returns the logged on username to variable: User<\/p>\n<p>&#8216;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<\/p>\n<p>CName = UCase(sys) &#8216;Get name from network object (Uppercase)<br \/>\nSet oNet = CreateObject(&#8220;WScript.Network&#8221;)<br \/>\n&#8216;<br \/>\n&#8216; -=( Add printer and set a default based on computer name (CName) )=-<br \/>\n&#8216;<\/p>\n<p>&#8216; Test for Left(CName,NumberofChars)<\/p>\n<p>&#8216; WEST BLOCK SCRIPTS<\/p>\n<p>if Left(CName,3) = &#8220;W21&#8221; Then<\/p>\n<p>oNet.AddWindowsPrinterConnection &#8220;\\print-serverw21-mono&#8221;<br \/>\noNet.AddWindowsPrinterConnection &#8220;\\print-serverw21-colour&#8221;<br \/>\noNet.SetDefaultPrinter &#8220;\\print-serverw21-mono&#8221;<\/p>\n<p>Elseif Left(CName,3) = &#8220;W22&#8221; Then<\/p>\n<p>oNet.AddWindowsPrinterConnection &#8220;\\print-serverw22-Mono&#8221;<br \/>\noNet.AddWindowsPrinterConnection &#8220;\\print-serverw22-Colour&#8221;<br \/>\noNet.SetDefaultPrinter &#8220;\\print-serverw22-mono&#8221;<\/p>\n<p>etc etc<\/p>\n<p>end IF<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have been onto a site recently, and had issues with the Group Policy Preferences not applying to the printers. I found out that this was due to the time it takes the printer to respond to the request to be &#8220;mapped&#8221; and made default. I spent a few hours and hacked around some code &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/giraffeit.com\/index.php\/2011\/10\/27\/printer-scripts-for-windows-seven\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Printer Scripts for Windows Seven&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-392","post","type-post","status-publish","format-standard","hentry","category-bog"],"_links":{"self":[{"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/posts\/392","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/comments?post=392"}],"version-history":[{"count":0,"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/posts\/392\/revisions"}],"wp:attachment":[{"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/media?parent=392"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/categories?post=392"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/tags?post=392"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}