{"id":67663,"date":"2006-03-28T15:23:00","date_gmt":"2006-03-28T15:23:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2006\/03\/28\/how-can-i-disable-the-keep-printed-documents-attribute-on-a-printer\/"},"modified":"2006-03-28T15:23:00","modified_gmt":"2006-03-28T15:23:00","slug":"how-can-i-disable-the-keep-printed-documents-attribute-on-a-printer","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-disable-the-keep-printed-documents-attribute-on-a-printer\/","title":{"rendered":"How Can I Disable the Keep Printed Documents Attribute on a Printer?"},"content":{"rendered":"<p><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\"> \n<P>Hey, Scripting Guy! How can I disable the Keep Printed Documents attribute on a printer?<BR><BR>&#8212; JJ<\/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, JJ. You didn\u2019t mention which operating system you\u2019re trying to do this on, but we hope it\u2019s a Windows XP or Windows Servers 2003 computer. Why? Well, on a Windows XP or Windows Server 2003 machine, this is easy; on any other version of Windows it\u2019s a bit harder. How much harder? Well, to tell you the truth, it\u2019s downright impossible.<\/P>\n<P>Which <I>definitely<\/I> makes the task a bit harder to carry out.<\/P>\n<P>Yes, we know: that <I>isn\u2019t<\/I> fair. But such is life. With Windows XP, the WMI class <B>Win32_Printer<\/B> was upgraded to include a new read\/write property: <B>KeepPrintedJobs<\/B>. As you might have guessed, we can simply toggle this property value back-and-forth to keep (or not keep) printer jobs for a specified printer. Unfortunately, this property does not exist on any version of Windows prior to Windows XP. With, say, Windows 2000, we can use a script to tell whether or not this attribute is enabled for a printer, but we can\u2019t actually change the value. <\/P>\n<TABLE id=\"EID\" class=\"dataTable\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\"><B>Note<\/B>. Sadly, ADSI &#8211; which often provides a handy workaround for printer management in Windows 2000 &#8211; is of little use to us here. There <I>is<\/I> a new ADSI attribute for configuring the Keep Printed Documents property but it won\u2019t do you any good on a Windows 2000 computer, either.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>Assuming that you <I>are<\/I> using Windows XP or Windows Server 2003, however, then you can disable the Keep Printed Documents property by using a script like this:<\/P><PRE class=\"codeSample\">strComputer = &#8220;.&#8221;\nSet objWMIService = GetObject(&#8220;winmgmts:\\\\&#8221; &amp; strComputer &amp; &#8220;\\root\\cimv2&#8221;)<\/p>\n<p>Set colPrinters = objWMIService.ExecQuery _\n    (&#8220;Select * From Win32_Printer Where DeviceID = &#8216;ArtDepartmentPrinter'&#8221;)<\/p>\n<p>For Each objPrinter in colPrinters\n    objPrinter.KeepPrintedJobs = False\n    objPrinter.Put_\nNext\n<\/PRE>\n<P>We know: it seems <I>really<\/I> unfair that you can\u2019t do this at all on Windows 2000 yet the script is so remarkably simple for Windows XP and Windows Server 2003. (Did we mention that life isn\u2019t fair? Well, it\u2019s not.) Our script for modifying the KeepPrintedJobs property is a run-of-the-mill WMI script, one that starts out by connecting to the WMI service on the local computer. (Although, as usual, this works just as well on remote computers.) We then issue this query to return a collection of all the printers on the computer that have a <B>DeviceID<\/B> of <I>ArtDepartmentPrinter<\/I>:<\/P><PRE class=\"codeSample\">Set colPrinters = objWMIService.ExecQuery _\n    (&#8220;Select * From Win32_Printer Where DeviceID = &#8216;ArtDepartmentPrinter'&#8221;)\n<\/PRE>\n<P>Keep in mind that we did this because you specifically asked about changing the property value on <I>a<\/I> printer. In some cases, however, you might want to modify this property value for <I>all<\/I> the printers on a print server. If that\u2019s the case, then simply remove the Where clause from the query. This query returns a collection of <I>all<\/I> the printers on a computer, enabling you to change the KeepPrintedJobs property for, say, each for the 150 or so printers on a print server:<\/P><PRE class=\"codeSample\">Set colPrinters = objWMIService.ExecQuery(&#8220;Select * From Win32_Printer&#8221;)\n<\/PRE>\n<P>And yes, that <I>is<\/I> why we like WMI so much. <\/P>\n<P>As soon as we have our collection we set up a For Each loop to walk us through all the printers in the collection (again, for this particular script we\u2019ll have only one printer, the printer with the DeviceID ArtDepartmentPrinter). Inside our For Each loop we find these two lines of code:<\/P><PRE class=\"codeSample\">objPrinter.KeepPrintedJobs = False\nobjPrinter.Put_\n<\/PRE>\n<P>Here we\u2019re doing nothing more than setting the value of the KeepPrintedJobs property to False, then calling the <B>Put_<\/B> method to actually save those changes to the printer. From this point on, ArtDepartmentPrinter will no longer save a copy of printed documents. That\u2019s all there is to it.<\/P>\n<P>As we noted earlier, you can\u2019t modify this property on a Windows 2000 computer; you can, however, determine whether or not this property has been enabled on a Windows 2000 computer. This isn\u2019t much of a consolation prize, but here\u2019s a script that will do just that:<\/P><PRE class=\"codeSample\">strComputer = &#8220;.&#8221;<\/p>\n<p>Set objWMIService = GetObject(&#8220;winmgmts:\\\\&#8221; &amp; strComputer &amp; &#8220;\\root\\cimv2&#8221;)\nSet colPrinters = objWMIService.ExecQuery _\n    (&#8220;Select * From Win32_Printer Where DeviceID = &#8216;ArtDepartmentPrinter'&#8221;)<\/p>\n<p>For Each objPrinter in colPrinters\n    If objPrinter.Attributes And 256 Then \n        Wscript.Echo &#8220;Printed documents are kept.&#8221;\n    Else\n        Wscript.Echo &#8220;Printed documents are not kept.&#8221;\n    End If\nNext\n<\/PRE>\n<P>On a Windows 2000 computer, the KeepPrintedJobs property is part of a read-only \u201cbitmask\u201d property called <B>Attributes<\/B>. We won\u2019t discuss bitmasks or the Attributes property in any detail today; instead we\u2019ll simply point out that the KeepPrintedJobs property has an attribute value of 256. Because of that, we can use Boolean logic to determine whether KeepPrintedJobs is enabled or not. If this line of code is true, that means KeepPrintedJobs has been enabled:<\/P><PRE class=\"codeSample\">If objPrinter.Attributes And 256 Then\n<\/PRE>\n<P>Sure, it looks weird, but think of it in these terms: imagine there\u2019s a switch on the computer that has a value of 256. If that switch is on then KeepPrintedJobs is enabled; if that switch is off then KeepPrintedJobs is disabled. All we\u2019re doing is checking to see whether or not that switch is on or off.<\/P>\n<P>Incidentally, and before you ask, we\u2019re afraid the answer is no: it\u2019s highly unlikely the version of WMI found on Windows 2000 will ever be updated to allow you to modify the KeepPrintedJobs property. Sorry.<\/P>\n<P>Now, let\u2019s see, is there any <I>more<\/I> bad news we can tell you about today? Well, now that you mention it\u2026.<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I disable the Keep Printed Documents attribute on a printer?&#8212; JJ Hey, JJ. You didn\u2019t mention which operating system you\u2019re trying to do this on, but we hope it\u2019s a Windows XP or Windows Servers 2003 computer. Why? Well, on a Windows XP or Windows Server 2003 machine, this is [&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":[712,523,404,713,3,5],"class_list":["post-67663","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-and-jobs","tag-print-servers","tag-printing","tag-queues","tag-scripting-guy","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! How can I disable the Keep Printed Documents attribute on a printer?&#8212; JJ Hey, JJ. You didn\u2019t mention which operating system you\u2019re trying to do this on, but we hope it\u2019s a Windows XP or Windows Servers 2003 computer. Why? Well, on a Windows XP or Windows Server 2003 machine, this is [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/67663","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=67663"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/67663\/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=67663"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=67663"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=67663"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}