Link to home
Start Free TrialLog in
Avatar of samiam41
samiam41Flag for United States of America

asked on

combine actions in a batch script

Greetings experts!!  I have two actions that I would like a batch file to perform.  The first action is delete the value "oldserver" out of the HKCU>Printers>Settings and then delete out "oldserver" from HKCU>Printers>Connections.

I am using this script and wanted to build off of it accordingly (a product of an EE expert):
@echo off
setlocal

set Server=oldserver

for /f "tokens=*" %%A in ('reg query "HKEY_CURRENT_USER\Printers\Connections" ^| find /i ",%Server%,"') do (
  reg delete "%%~A" /f
) 

Open in new window


I tried to add this:  

for /f "tokens=*" %%A in ('reg query "HKEY_CURRENT_USER\Printers\Settings" ^| find /i ",%server%,"') do (
  reg delete "%%~A" /f

but couldn't get it to work.  Please help combine these two actions into a single batch script.  Thanks experts!
Avatar of Bill Prew
Bill Prew

Try this:

for /f "tokens=1" %%A in ('reg query "HKEY_CURRENT_USER\Printers\Settings" ^| find /i "\\%Server%\"') do (
  echo reg delete "HKEY_CURRENT_USER\Printers\Settings" /v "%%~A" /f
)

Open in new window

~bp
Avatar of samiam41

ASKER

BP, how do I combine the "settings" and "connections" variables?  You have "settings" listed twice.
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Spot on and another great solution.  Thanks BP!
Welcome, thanks for the feedback.

~bp