{"id":69923,"date":"2005-04-28T03:21:00","date_gmt":"2005-04-28T03:21:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2005\/04\/28\/how-can-i-purge-all-the-print-jobs-on-a-windows-2000-print-server\/"},"modified":"2005-04-28T03:21:00","modified_gmt":"2005-04-28T03:21:00","slug":"how-can-i-purge-all-the-print-jobs-on-a-windows-2000-print-server","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-purge-all-the-print-jobs-on-a-windows-2000-print-server\/","title":{"rendered":"How Can I Purge All the Print Jobs on a Windows 2000 Print Server?"},"content":{"rendered":"<p><H2><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\"> <\/H2>\n<P>Hey, Scripting Guy! How can I purge all the print jobs on a Windows 2000 print server?<BR><BR>&#8212; KC<\/P><IMG border=\"0\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" height=\"5\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\"><A href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><IMG class=\"farGraphic\" title=\"Script Center\" border=\"0\" alt=\"Script Center\" align=\"right\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" height=\"288\"><\/A> \n<P>Hey, KC. This is one of those questions we hate, not because we don\u2019t have an answer for it &#8211; we do &#8211; but because we have to temporarily abandon one of the core tenets of the Scripting Guy Way of Life. That tenet &#8211; just a second while we blow the dust off it- is this: ADSI should be used for managing Active Directory and other directory services (including local computer accounts); WMI should be used for everything else.<\/P>\n<P>Ok, so maybe it\u2019s <I>not<\/I> the 10 Commandments or the Golden Rule. But hey, we\u2019re <I>scripting <\/I>guys, not philosophy guys.<\/P>\n<P>Although ours is a simple way of life, most of the time this tenet works just fine. For example, suppose you\u2019re using Windows XP or Windows Server 2003 as a print server. Want to delete all the print jobs running on that computer? All you do is use a WMI script, just like we told you to:<\/P><PRE class=\"codeSample\">strComputer = &#8220;.&#8221;\nSet objWMIService = GetObject(&#8220;winmgmts:\\\\&#8221; &amp; strComputer &amp; &#8220;\\root\\cimv2&#8221;)<\/p>\n<p>Set colInstalledPrinters = objWMIService.ExecQuery _\n    (&#8220;Select * from Win32_Printer&#8221;)<\/p>\n<p>For Each objPrinter in colInstalledPrinters\n    objPrinter.CancelAllJobs()\nNext\n<\/PRE>\n<P>But what if you\u2019re using a Windows 2000 computer as a print server? Well, in that case we have a problem: the <B>CancelAllJobs()<\/B> method &#8211; used to delete print jobs from a printer on Windows XP and Windows Server 2003 &#8211; doesn\u2019t exist on Windows 2000. Not only that, but there\u2019s no comparable method to be found anywhere in the WMI repository. The cold, hard fact of the matter: you can\u2019t use WMI to delete all the print jobs on a Windows 2000 computer.<\/P>\n<P>Now, people of good moral fiber would simply stop at this point; after all, they would never compromise their principles just to delete a bunch of print jobs on a print server. We Scripting Guys have no such qualms, however; therefore, here\u2019s an ADSI script that can delete all the print jobs on a Windows 2000 computer:<\/P><PRE class=\"codeSample\">Set objComputer = GetObject(&#8220;WinNT:\/\/atl-ps-01&#8221;)\nobjComputer.Filter = Array(&#8220;printQueue&#8221;)<\/p>\n<p>For Each objPrinter in objComputer\n    objPrinter.Purge \nNext\n<\/PRE>\n<P>As you can see, we begin by using the WinNT provider to connect to the print server atl-ps-01. (By the way, <B>WinNT<\/B> is case-sensitive; your script will fail if you try using winnt or WINNT or any other variation.) This returns a collection of all the \u201cthings\u201d on atl-ps-01, or at least all the things ADSI knows about: user accounts, groups, services, and &#8211; hey! &#8211; printers. Because we only care about the printers we apply a <B>Filter<\/B> that limits the returned data to <B>printQueue<\/B> objects; as you might expect, printQueue is the ADSI designation for a printer object. The filter requires just one line of code:<\/P><PRE class=\"codeSample\">objComputer.Filter = Array(&#8220;printQueue&#8221;)\n<\/PRE>\n<P>Incidentally, the object we\u2019re filtering on &#8211; printQueue &#8211; must be configured as an array. This code <I>looks<\/I> like it should work, but it won\u2019t:<\/P><PRE class=\"codeSample\">objComputer.Filter = &#8220;printQueue&#8221;\n<\/PRE>\n<P>All that\u2019s left now is to loop through the collection of printers and &#8211; for each printer found &#8211; delete all the print jobs, something we can do using the <B>Purge<\/B> command. Deleting all the print jobs on all the printers takes just three lines of code:<\/P><PRE class=\"codeSample\">For Each objPrinter In objComputer\n    objPrinter.Purge \nNext\n<\/PRE>\n<P>Not too bad, huh? If you\u2019d like more information about managing print servers on Windows 2000 you might check out the <A href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/guide\/sas_prn_overview.mspx\" target=\"_blank\"><B>Printing chapter<\/B><\/A> in the Microsoft Windows 2000 Scripting Guide. And if you\u2019d like more information about breaking the rules, just keep reading this column; we\u2019re bound to break a few more before we\u2019re through.<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I purge all the print jobs on a Windows 2000 print server?&#8212; KC Hey, KC. This is one of those questions we hate, not because we don\u2019t have an answer for it &#8211; we do &#8211; but because we have to temporarily abandon one of the core tenets of the [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[9,712,23,24,523,404,713,3,4,5],"class_list":["post-69923","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-adsi","tag-and-jobs","tag-local-accounts-and-windows-nt-4-0-accounts","tag-other-directory-services","tag-print-servers","tag-printing","tag-queues","tag-scripting-guy","tag-scripting-techniques","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! How can I purge all the print jobs on a Windows 2000 print server?&#8212; KC Hey, KC. This is one of those questions we hate, not because we don\u2019t have an answer for it &#8211; we do &#8211; but because we have to temporarily abandon one of the core tenets of the [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/69923","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=69923"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/69923\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=69923"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=69923"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=69923"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}