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!
Printer Redirection Batch Help
Moderator: DosItHelp
Re: Printer Redirection Batch Help
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.
Re: Printer Redirection Batch Help
I didn't see a way to attach anything. The script inside my batch file right now is this:
It does work to delete the redirected printers but just was not sure how to get it to exclude certain ones.
Thanks Squashman!
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!
Re: Printer Redirection Batch Help
Which ones? you need to tell us!bcskc620 wrote:It does work to delete the redirected printers but just was not sure how to get it to exclude certain ones.
Re: Printer Redirection Batch Help
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
Universal Printer
Re: Printer Redirection Batch Help
This may work but is not the kind of solution I'd be recommending.I'd suggest you save the Universal Printer key value and data, delete all values as before then reintroduce the information you wanted keeping.
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
Re: Printer Redirection Batch Help
Thanks Compo. I'll give this a try.