{"id":68423,"date":"2005-12-01T13:44:00","date_gmt":"2005-12-01T13:44:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2005\/12\/01\/how-can-i-remove-all-the-local-printers-from-a-computer\/"},"modified":"2005-12-01T13:44:00","modified_gmt":"2005-12-01T13:44:00","slug":"how-can-i-remove-all-the-local-printers-from-a-computer","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-remove-all-the-local-printers-from-a-computer\/","title":{"rendered":"How Can I Remove All the Local Printers from a Computer?"},"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 remove all the local printers from a computer?<BR><BR>&#8212; JW<\/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, JW. You <I>did<\/I> say that you wanted to do this only on computers running Windows XP or Windows Server 2003, didn\u2019t you? You didn\u2019t? Oh. Well, we\u2019re going to pretend that you did, because this is a very easy task to carry out on Windows XP and Windows Server 2003. That\u2019s because on Windows XP and Windows Server 2003 the WMI class <B>Win32_Printer<\/B> not only can easily distinguish between local printers and network printers, but it also supports the <B>Delete_<\/B> method. As you can probably guess, that method enables you to delete printer connections. In other words, WMI lets you pick out and remove local printers. Which, all in all, sounds exactly like the answer to your question.<\/P>\n<P>That\u2019s the good news. The bad news is that, on earlier versions of Windows, it\u2019s more complicated to pick out local printers; even worse, the Win32_Printer class doesn\u2019t support the Delete_ method. That means it\u2019s far more challenging to identify and remove local printers. Because of that we\u2019re going to focus on removing local printers from Windows XP and Windows Server 2003 computers and hope that takes care of your problem. If not, we\u2019ll have to tackle printer removal on Windows 2000 computers at a later date.<\/P>\n<P>For Windows XP and Windows Server 2003 users you can delete all the local printers using a script as simple as 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 colInstalledPrinters =  objWMIService.ExecQuery _\n    (&#8220;Select * from Win32_Printer Where Network = FALSE&#8221;)<\/p>\n<p>For Each objPrinter in colInstalledPrinters\n    objPrinter.Delete_\nNext\n<\/PRE>\n<P>This script begins by connecting to the WMI service on the local computer (although it can be easily modified to remove printers from a remote computer instead). We then use this line of code to return a collection of all the local printers; as far as WMI is concerned, a printer is a local printer if the <B>Network<\/B> property is set to False:<\/P><PRE class=\"codeSample\">Set colInstalledPrinters =  objWMIService.ExecQuery _\n    (&#8220;Select * from Win32_Printer Where Network = FALSE&#8221;)\n<\/PRE>\n<P>Once we have a collection of local printers we simply set up a For Each loop to walk through that collection, calling the Delete_ method (note the underscore on the end) for each printer in the collection:<\/P><PRE class=\"codeSample\">For Each objPrinter in colInstalledPrinters\n    objPrinter.Delete_\nNext\n<\/PRE>\n<P>There you have it: that will delete all the local printers, while leaving the network printer connections alone. <I>Now<\/I> aren\u2019t you glad that you asked about removing local printers specifically from Windows XP and Windows Server 2003 computers without giving any thought whatsoever to earlier versions of the operating system? <\/P>\n<P>OK, fine: we\u2019ll see what we can do about addressing this issue on Windows 2000 computers. We won\u2019t make any promises, but we\u2019ll look into it.<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I remove all the local printers from a computer?&#8212; JW Hey, JW. You did say that you wanted to do this only on computers running Windows XP or Windows Server 2003, didn\u2019t you? You didn\u2019t? Oh. Well, we\u2019re going to pretend that you did, because this is a very easy [&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":[445,404,3,4,5,6],"class_list":["post-68423","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-client-side-printing","tag-printing","tag-scripting-guy","tag-scripting-techniques","tag-vbscript","tag-wmi"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! How can I remove all the local printers from a computer?&#8212; JW Hey, JW. You did say that you wanted to do this only on computers running Windows XP or Windows Server 2003, didn\u2019t you? You didn\u2019t? Oh. Well, we\u2019re going to pretend that you did, because this is a very easy [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/68423","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=68423"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/68423\/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=68423"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=68423"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=68423"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}