kpezza38 Posted February 15, 2016 Posted February 15, 2016 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.
dapaulio Posted February 15, 2016 Posted February 15, 2016 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.
kpezza38 Posted February 17, 2016 Author Posted February 17, 2016 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.
Duke5A Posted February 19, 2016 Posted February 19, 2016 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
kpezza38 Posted February 22, 2016 Author Posted February 22, 2016 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.
Arthur Posted February 22, 2016 Posted February 22, 2016 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
shabbaranks Posted February 22, 2016 Posted February 22, 2016 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
kpezza38 Posted February 22, 2016 Author Posted February 22, 2016 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.
dapaulio Posted February 23, 2016 Posted February 23, 2016 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now