Jump to content

Recommended Posts

Posted

Hi Everyone,

 

I was thinking of deleting the old printers via User Config > Control Panel Settings > Printers but I am not sure if this will remove the printer drivers, which I don't want it to do. I only need to target network printers that were created from the old print server, so I was also thinking a vb script would be good but I'm not sure where to start. We can't use Powershell due to security constraints, so that is out of the question.

 

If anyone can shed some light on the subject for me I would appreciate it. For now I will continue researching and testing.

Posted

I have tried removing printers via gp before and don't think the driver is uninstalled off the client.

I started to do this and thought there must be an easier way. So I scripted it using printx.exe /f switch if I recall then used scripts on a logon script. You would need to enable the policy loop back option set to merged.

Posted

OK, so I have the following script (from the web), which works when testing but isn't working when it is run from a GPO (script set on LogOff):

 

On Error Resume Next

 

 

Dim arrPrinterName()

Dim strComputer, i, PrintServer

Dim objWMIService, objNetwork, colInstalledPrinters, objPrinter

 

 

strComputer = "."

i = 0

PrintServer = "Printer Server"

 

 

Set objWMIService = GetObject("winmgmts:" _

& "{impersonationLevel=impersonate}!" & strComputer & "\root\cimv2")

 

 

Set colInstalledPrinters = objWMIService.ExecQuery _

("Select * from Win32_Printer")

 

 

For Each objPrinter in colInstalledPrinters

 

 

ReDim Preserve arrPrinterName(i)

arrPrinterName(i) = objPrinter.Name

If InStr(arrPrinterName(i), PrintServer) Then

Set objNetwork = WScript.CreateObject("WScript.Network")

objNetwork.RemovePrinterConnection arrPrinterName(i)

i=i+1

End If

Next

 

I need to have the script run on logoff and not logon, as any delay in logon and the users will have a fit. I'm not sure why this won't work on logoff but I am going to be testing it today. If anyone has any thoughts please let me know.

Posted

A little cleaner version of the above script. I've used this to do exactly what you're looking to do now.

 

Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery("Select * from Win32_Printer",,48)
Set objNetwork = CreateObject("Wscript.Network")

For Each objPrinter in colInstalledPrinters
If InStr(LCase(objPrinter.Name), "SERVER NAME GOES HERE") Then
	objNetwork.RemovePrinterConnection objPrinter.Name
End If
Next

Posted
Duke5A, that script is nice but unfortunately doesn't work for me. I am now going to attempt to use brute force to remove the printers because this has dragged on too long.
Posted
A little cleaner version of the above script.

Even cleaner version (using the VBS printer scripts Microsoft includes with Windows). :)

 

cscript %SystemRoot%\System32\Printing_Admin_Scripts\en-US\Prnmngr.vbs -d -p TheNameOfThePrinterToRemove

Posted

This should delete the printers

 

Set WshNetwork = WScript.CreateObject("WScript.Network")
Set oPrinters = WshNetwork.EnumPrinterConnections
Set WshShell = CreateObject("WScript.Shell")
Set objWMIService = GetObject("winmgmts:") 
Dim allPrinters(99, 2)
Dim foundFlag
Dim searchName
Dim i, count

'Deletes any currently installed queue based printers
WshShell.Run ("rundll32 printui.dll,PrintUIEntry /q /dl /n " & chr(34) & "Enter Printer Name Here" & chr(34)) 

End If 
'End of Script
Wscript.Quit

Posted
My script works, it just doesn't work when it is attached to a Group Policy to run at Logon or Logoff (user) or Startup or Shutdown (computer). It looks like it isn't even being applied to the user account or the computer but the policy is enabled and the scope is set for filtering to my account for the moment.
Posted
My script works, it just doesn't work when it is attached to a Group Policy to run at Logon or Logoff (user) or Startup or Shutdown (computer). It looks like it isn't even being applied to the user account or the computer but the policy is enabled and the scope is set for filtering to my account for the moment.

 

Have you tried setting group policy loopback - setting to merge

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...