Solved

combine actions in a batch script

Posted on 2014-01-24
5
538 Views
Last Modified: 2014-01-27
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!
0
Comment
Question by:samiam41
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 54

Expert Comment

by:Bill Prew
ID: 39807668
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
0
 
LVL 9

Author Comment

by:samiam41
ID: 39807679
BP, how do I combine the "settings" and "connections" variables?  You have "settings" listed twice.
0
 
LVL 54

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 39807719
Full script would look like this.  In one case you are deleting just one value (from settings) in the other case you are deleting the whole key (connections).

@echo off
setlocal

set Server=oldserver

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

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

Open in new window

~bp
0
 
LVL 9

Author Closing Comment

by:samiam41
ID: 39812280
Spot on and another great solution.  Thanks BP!
0
 
LVL 54

Expert Comment

by:Bill Prew
ID: 39812382
Welcome, thanks for the feedback.

~bp
0

Featured Post

Create Professional Looking Email Signatures

Create "Professional HTML Email Signatures" with ease.
7 Day Money Back Guarantee if not 100% Satisfied.
Affordable - Try it out for 7 Days Totally Risk Free.
Installers provided for over 45 Email clients.
Both Windows & MAC Supported.
Highly Recommended!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

OfficeMate Freezes on login or does not load after login credentials are input.
There are many software programs on offer that will claim to magically speed up your computer. The best advice I can give you is to avoid them like the plague, because they will often cause far more problems than they solve. Try some of these "do it…
This Micro Tutorial will teach you the basics of configuring your computer to improve its speed. It will also teach you how to disable programs that are running in the background simultaneously. This will be demonstrated using Windows 7 operating…
This Micro Tutorial will give you a basic overview of Windows Live Photo Gallery and show you various editing filters and touches to photos you can apply. This will be demonstrated using Windows Live Photo Gallery on Windows 7 operating system.

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question