logo

The ConnectWise Control forum has moved to ConnectWise University! This forum has been locked and is in read-only mode. Click here for instructions on how to access the new forum.

Welcome Guest! You can not login or register.

Notification

Icon
Error

Options
Go to last post Go to first unread
jproos  
#1 Posted : Friday, July 31, 2015 2:19:34 AM(UTC)
jproos


Rank: Member

Medals: Level 1: Random Act of Kindness! Received One Thanks!

Joined: 10/27/2014(UTC)
Posts: 22
United States

Thanks: 3 times
Was thanked: 2 time(s) in 2 post(s)
If you find yourself with a bunch of computers that have a bunch of orphaned ScreenConnect created printers on them. These scripts might be helpful. I used scripts very close to these to clean up my own network. This saved me having manually remove hundreds of printers from dozens of computers. I used 2 scripts with a little bit of manual editing to construct the second from the output of the first. Both scripts depend on the SysInternals utility psexec.exe.

This first script calls some VB code that is included in Windows 7/8/8.1. The first parameter (%1) to the script is the network name of the PC which has the printers you want to remove. The second parameter (%2) is the name that SC used when it named of each of the printers (e.g. for a printer named "HP 8150 (Steve)" you would use "Steve". Both parameters are case insensitive. Save the script as .BAT file and execute it from a command line using an account which processes admin privileges on the remote PC. You might not need admin credentials for this one but I didn't try it without admin credentials. The output file will have the value of the first parameter in the file name (e.g. c:\temp\Printers-JimsPC.txt) it will contain the full name of each printer that had the value of the second parameter in its name at least once. The output file will be written to the computer where the script is executed from.

mkdir c:\temp
psexec.exe \\%1 cscript.exe c:\Windows\SYStem32\printing_admin_scripts\en-us\prnmngr.vbs -l > c:\temp\All-Printers-%1.txt
find /i "%2" c:\temp\All-Printers-%1.txt > c:\temp\Printers0-%1.txt
find /i "Printer Name" c:\temp\Printers0-%1.txt > c:\temp\Printers-%1.txt
del c:\temp\All-Printers-%1.txt
del c:\temp\Printers0-%1.txt


Here's an example call of the first .bat script:

c:\get-printer-list.bat JimsPC Steve

Now open c:\temp\Printers-xxxxx.txt and edit it to look like below. This script calls the built-in Windows printui.exe utility to remove each printer. Your printer names will not contain the ?????, of course and obviously you'll have different printers listed. This script has one parameter (%1) which is the name of the remote PC again. This parameter is case insensitive. Save this file as .BAT file and execute it from a command line using an account which processes admin privileges on the remote PC. This time I'm pretty certain that you will need to use admin credentials for this one. There is no output file from this script.

PsExec.exe \\%1 printui.exe /dl /n "PsExec.exe \\%1 printui.exe /dl /n "WebEx Document Loader (??????)" /q
PsExec.exe \\%1 printui.exe /dl /n "Snagit 12 (??????)" /q
PsExec.exe \\%1 printui.exe /dl /n "SnagIt 10 (??????)" /q
PsExec.exe \\%1 printui.exe /dl /n "Sage 50 E-mail Writer v2 (??????)" /q
PsExec.exe \\%1 printui.exe /dl /n "Microsoft Office Document Image Writer (??????)" /q
PsExec.exe \\%1 printui.exe /dl /n "Lexmark Universal v2 XL (??????)" /q
PsExec.exe \\%1 printui.exe /dl /n "Lexmark CS410 Series PS3 (??????)" /q
PsExec.exe \\%1 printui.exe /dl /n "ISI Printer (??????)" /q
PsExec.exe \\%1 printui.exe /dl /n "ISI LSPrinter (??????)" /q
PsExec.exe \\%1 printui.exe /dl /n "HP MFP Send Fax (??????)" /q


Here's an example call of the second .bat script:

c:\delete-printers.bat JimsPC

At this point the printers should be gone from the remote PC. You can check that by running the first script again exactly the same way you ran it the first time. The output file should have a header line but no printers in it. If it does list any printers then my experience is that there may be print jobs in the queue and that you will need to purge the print queue before you can delete the printer. I don't know how to do that remotely so you're possibly faced with doing it in an SC session.

Many thanks to SC tech support for pointing me to the printui.exe command in the second script.

With PowerShell you could probably combine all of this into one completely automated process and also probably avoid using psexec.exe

Jason

Edited by user Monday, August 3, 2015 6:48:07 PM(UTC)  | Reason: typo

shawnkhall  
#2 Posted : Friday, October 2, 2015 5:54:06 AM(UTC)
shawnkhall


Rank: Advanced Member

Medals: Level 1: Random Act of Kindness! Received One Thanks!

Joined: 2/6/2014(UTC)
Posts: 316
Man
United States

Thanks: 6 times
Was thanked: 33 time(s) in 29 post(s)
There's a much simpler way to remove these printers under Windows using the ScreenConnect "Commands" feature:
Code:
wmic printer where "name LIKE '%%shawnkhall%%'" delete


Replace my username (shawnkhall) with your ScreenConnect login name. This is the unique string inserted into the remote printer names that are added on your behalf via ScreenConnect.

I run this for each user account in my cleanup routine. Something like this:
Code:
wmic printer where "name LIKE '%%shawnkhall%%'" delete
wmic printer where "name LIKE '%%myuser2%%'" delete
wmic printer where "name LIKE '%%myotheruser%%'" delete
wmic printer where "name LIKE '%%yetanotheruser%%'" delete
Andrul  
#3 Posted : Wednesday, April 4, 2018 2:25:53 PM(UTC)
Andrul


Rank: Guest

Joined: 4/4/2018(UTC)
Posts: 1
United States
Location: East Coast

We're on SC 6.5 and still having the orphans appear even though it's supposedly resolved. Shawnkhall's solution looks nice and simple, but where is the commands feature he mentioned?

Thanks
shawnkhall  
#4 Posted : Wednesday, April 4, 2018 3:53:48 PM(UTC)
shawnkhall


Rank: Advanced Member

Medals: Level 1: Random Act of Kindness! Received One Thanks!

Joined: 2/6/2014(UTC)
Posts: 316
Man
United States

Thanks: 6 times
Was thanked: 33 time(s) in 29 post(s)
Originally Posted by: Andrul Go to Quoted Post
where is the commands feature


The Commands feature is exposed via a button on the device toolbar near the right side:
Commands feature

You must have the 'rights' to use commands assigned to your user account to see it, but it's enabled by default.
ebell  
#5 Posted : Wednesday, April 4, 2018 8:03:11 PM(UTC)
ebell


Rank: Member

Medals: Level 1: Random Act of Kindness! Received One Thanks!

Joined: 5/13/2014(UTC)
Posts: 28
United States
Location: Texas

Thanks: 29 times
Was thanked: 6 time(s) in 4 post(s)
One other thing to mention, I ran across a couple of machines where the WMI command did not remove the printer. You can still use the printui utility mentioned in the original post; however, there is no need to user psexec. You can issue a

Code:
printui.exe /dl /c\\machine_name /n "HP MFP Send Fax (??????)" /q


to run the command on a remote machine. Something else to remember is that when you use the Commands tab of SC you are executing the command on the local system. So you can simply run:

Code:
printui.exe /dl /c\\machine_name /n "HP MFP Send Fax (??????)" /q


when

Code:
wmic printer where "name LIKE '%%username%%'" delete


doesn't work.

For those of you running against an older system that doesn't have the printui.exe file you can use the following command:

Code:
RUNDLL32.EXE PRINTUI.DLL,PrintUIEntry /dl /n "HP MFP Send Fax (??????)" /q
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.