Note that there are some explanatory texts on larger screens.

plurals
  1. PODelete Win7 network printer driver remotely using WMI
    primarykey
    data
    text
    <p>I need help with deleting network printer driver remotely on a <strong>Win7 client</strong> using a vbscript with an account having administrator privilegies on the computer in question. The problem is that I can't delete the connected printer the user have connected. Everything else seems to work. Below is the code for the script.</p> <p>The script does several things, but the ultimate goal is to fysically remove the printer-drivers. The current version of the script fails since the driver files are in use. The script contains code to avoid special printers. It also stops and starts the print spooler. </p> <pre><code>intSleep = 4000 strService = " 'Spooler' " strComputer = "&lt;remote computer name&gt;" Set fsobj = CreateObject("Scripting.FileSystemObject") 'Calls the File System Object Set objNetwork = CreateObject("WScript.Network") arrPrinters = Array("PDF", "Adobe", "Remote", "Fax", "Microsoft", "Send To", "Generic") Set objWMIService = GetObject("winmgmts:" _ &amp; "{impersonationLevel=impersonate}!\\" &amp; strComputer &amp; "\root\cimv2") ' List drivers Set colInstalledPrinters = objWMIService.ExecQuery _ ("Select * from Win32_PrinterDriver") Set drivrutinCol = CreateObject("Scripting.Dictionary") For each objPrinter in colInstalledPrinters ' Wscript.Echo "Configuration File: " &amp; objPrinter.ConfigFile ' Wscript.Echo "Data File: " &amp; objPrinter.DataFile ' Wscript.Echo "Description: " &amp; objPrinter.Description ' Wscript.Echo "Driver Path: " &amp; objPrinter.DriverPath ' Wscript.Echo "File Path: " &amp; objPrinter.FilePath ' Wscript.Echo "Help File: " &amp; objPrinter.HelpFile ' Wscript.Echo "INF Name: " &amp; objPrinter.InfName ' Wscript.Echo "Monitor Name: " &amp; objPrinter.MonitorName ' Wscript.Echo "Name: " &amp; objPrinter.Name ' Wscript.Echo "OEM Url: " &amp; objPrinter.OEMUrl ' Wscript.Echo "Supported Platform: " &amp; objPrinter.SupportedPlatform ' Wscript.Echo "Version: " &amp; objPrinter.Version if InArray(objPrinter.Name, arrPrinters ) = False then Wscript.Echo "Name: " &amp; objPrinter.Name drivrutinCol.Add drivrutinCol.Count, Replace(objPrinter.ConfigFile, "C:", "\\" &amp; strComputer &amp; "\c$") drivrutinCol.Add drivrutinCol.Count, Replace(objPrinter.DataFile, "C:", "\\" &amp; strComputer &amp; "\c$") drivrutinCol.Add drivrutinCol.Count, Replace(objPrinter.DriverPath, "C:", "\\" &amp; strComputer &amp; "\c$") end if Next ' Remove network printers Const NETWORK = 22 Set colInstalledPrinters = objWMIService.ExecQuery _ ("Select * From Win32_Printer") For Each objPrinter in colInstalledPrinters If objPrinter.Attributes And NETWORK Then ' The code never gets here for user connected network printers End If Next ' Stop Print Spooler Service Set colListOfServices = objWMIService.ExecQuery _ ("Select * from Win32_Service Where Name ="_ &amp; strService &amp; " ") For Each objService in colListOfServices objService.StopService() WSCript.Sleep intSleep Next ' Delete drivers for i = 0 to drivrutinCol.Count-1 Wscript.Echo "Deleting driver: " &amp; drivrutinCol.Item(i) fsobj.DeleteFile(drivrutinCol.Item(i)) Next ' Start Print Spooler Service For Each objService in colListOfServices WSCript.Sleep intSleep objService.StartService() Next Function InArray(item,myarray) Dim i For i=0 To UBound(myarray) Step 1 If InStr(lcase(item), lcase(myarray(i)))&gt;0 Then InArray=True Exit Function End If Next InArray=False End Function </code></pre> <p>The part where the code is not working is the "<strong>Remove network printers</strong>" - part. The script do not list the network printers that the user have connected in the userprofile, only the local printers connected to the computer profile. When the user printer is not removed, we cannot delete the drivers.</p> <p>Any help in how to solve this issue is very appreciated!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload