Windows 10 2004 & 20H2 not running VBS script to remove network printers

drackel 1 Reputation point
2020-12-09T18:11:50.353+00:00

Script to remove all network printers:

'REMOVE ALL NETWORK PRINTERS
strComputer = "."
Set objWMIService = GetObject("winmgmts:\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * From Win32_Printer Where Network = True")
For Each objPrinter in colInstalledPrinters
objPrinter.Delete_
Next


Windows 10 builds and script run status:

1) Version 1909
OS build 18362.1198

Script status – script runs successfully

2) Version 2004
OS build 19041.662

Script status – script run error

3) Version 20H2
OS build 19042.662

Script status – script run error

SCRIPT RUN ERROR:

Script: C:\REMOVE-N-PRINTERS.vbs
Line: 7
Char: 1
Error: Generic Failure
Code: 80041001
Source: SWbemObjectEx

Windows Server Printing
Windows Server Printing
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.Printing: Printer centralized deployment and management, scan and fax resources management, and document services
675 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Eleven Yu (Shanghai Wicresoft Co,.Ltd.) 10,756 Reputation points Microsoft Vendor
    2020-12-10T08:03:28.347+00:00

    Hi,

    Have you tried running the VBS scipt on different machines with Version 2004 & Version 20H2? Did all of them get the same error?

    If so, please first try below troubleshooting steps to see if any help.

    1. Start > Settings > Apps > Default apps > Choose default apps by file type > manually select "Microsoft Windows Based Script Host" again for .vbs extension > run script again to check if error
    2. Stop and restart winmgmts servuces
      Open command prompt > run net stop winmgmt > open Windows Explorer, navigate to %systemroot%\system32\wbem and delete the Repository directory > run net start winmgmt > run script again to check if error
    3. Re-register the dll file
      Open command prompt > run below commands:
      cd /d %windir%\system32\wbem
      for %i in (.dll) do RegSvr32 -s %i
      for %i in (
      .exe) do %i /RegServer

    If all above methods cannot resolve the error, please check if you can use the VBS script in below link to remove all network printers. I have done a lab test in my environment. My version is windows 2004 OS build 19041.572. I can run the script successfully.
    How to remove all network printers on a computer
    https://gallery.technet.microsoft.com/scriptcenter/How-to-remove-all-network-d3979e18

    Thanks,

    Eleven

    If the Answer is helpful, please click "Accept Answer" and upvote it. Thanks.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.