Printer Redirection Batch Help

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
bcskc620
Posts: 4
Joined: 20 Jun 2016 07:35

Printer Redirection Batch Help

#1 Post by bcskc620 » 20 Jun 2016 07:41

Hello all, I have a batch file set to run at user log off to clear redirected printers from HKCU > Software > Microsoft > Windows NT > CurrentVersion > Devices /f /va

This works great. However, I would like to specify a certain printer to not be removed when this batch file is run. The printer name is Universal Printer. Can anyone assist in editing the above batch file to delete all except specified?

Thank you!

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Printer Redirection Batch Help

#2 Post by Squashman » 20 Jun 2016 08:35

bcskc620 wrote: Can anyone assist in editing the above batch file to delete all except specified?

I don't see a batch file to assist you with.

bcskc620
Posts: 4
Joined: 20 Jun 2016 07:35

Re: Printer Redirection Batch Help

#3 Post by bcskc620 » 20 Jun 2016 09:31

I didn't see a way to attach anything. The script inside my batch file right now is this:


Code: Select all

reg delete "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Devices" /f /va



It does work to delete the redirected printers but just was not sure how to get it to exclude certain ones.

Thanks Squashman!

Compo
Posts: 600
Joined: 21 Mar 2014 08:50

Re: Printer Redirection Batch Help

#4 Post by Compo » 20 Jun 2016 10:54

bcskc620 wrote:It does work to delete the redirected printers but just was not sure how to get it to exclude certain ones.
Which ones? you need to tell us!

bcskc620
Posts: 4
Joined: 20 Jun 2016 07:35

Re: Printer Redirection Batch Help

#5 Post by bcskc620 » 20 Jun 2016 10:58

Sorry, figured it could be advised and I could just edit the file and add in the additional script. Thanks for your patience. The printer that I would like to not get deleted is called

Universal Printer

Compo
Posts: 600
Joined: 21 Mar 2014 08:50

Re: Printer Redirection Batch Help

#6 Post by Compo » 20 Jun 2016 12:06

This may work but is not the kind of solution I'd be recommending.

Code: Select all

@Echo Off
SetLocal EnableExtensions EnableDelayedExpansion

(Set _P=Universal Printer)

(Set _K=HKCU\Software\Microsoft\Windows NT\CurrentVersion\Devices)
For /F "Tokens=*" %%A In ('Reg Query "%_K%"^|Find "REG_"') Do Call :Sub %%A
Exit/B

:Sub
(Set _O=%*)
(Set _E=%_O:*  =  %)
If "!_O:%_E%=!" NEq "%_P%" Reg Delete "%_K%" /V "!_O:%_E%=!" /F
I'd suggest you save the Universal Printer key value and data, delete all values as before then reintroduce the information you wanted keeping.

bcskc620
Posts: 4
Joined: 20 Jun 2016 07:35

Re: Printer Redirection Batch Help

#7 Post by bcskc620 » 20 Jun 2016 12:35

Thanks Compo. I'll give this a try.

Post Reply