Solved

Formatting Batch Script Output

Posted on 2004-09-30
2
337 Views
Last Modified: 2010-04-19
I am using this command to put all of the names of the installed programs into a file: reg.exe query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /s | find "DisplayName" > SftWrInv_%computername%.txt

The problem is I need to remove everything on these lines except the actual program names. I'd like to have all the names on one line seperated by commas with no spaces as well. Here is a sample of the output as it is right now (the whitespaces are tabs):

    DisplayName      REG_SZ      Fathom
    DisplayName      REG_SZ      Microsoft Data Access Components KB870669
    QuietDisplayName      REG_SZ      Microsoft Data Access Components KB870669
    DisplayName      REG_SZ      LiveUpdate 1.80 (Symantec Corporation)
    DisplayName      REG_SZ      Macromedia Shockwave Player
    ParentDisplayName      REG_SZ      Windows XP - Software Updates

I don't know much about how to format text like this in a batch program. Anyone have an idea as to how I can do this? Thanks for your input.
0
Comment
Question by:Grime121
2 Comments
 
LVL 82

Accepted Solution

by:
oBdA earned 500 total points
Comment Utility
Something like that? This will set the variable "Programs" to a comma-separated list of the program names:

====8<----[Programs.cmd]----
@echo off
setlocal enabledelayedexpansion
set UninstallKey=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall

set Programs=
for /f "tokens=2*" %%a in ('reg.exe query %UninstallKey% /s ^| find /i "Displayname"') do (
  echo %%b
  set Programs=!Programs!,%%b
)
set Programs=%Programs:~1%
echo %Programs%
====8<----[Programs.cmd]----
0
 
LVL 1

Author Comment

by:Grime121
Comment Utility
Man, with all the batch script stuff you've written for me in the past few weeks maybe I should be giving you a paycheck :P

Thanks again.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Numerous times I have been asked this questions that what is it that makes my machine log on so slow, there have been cases where computers took 23 minute exactly after taking password and getting to the desktop. Interesting thing was the fact th…
On July 14th 2015, Windows Server 2003 will become End of Support, leaving hundreds of thousands of servers around the world that still run this 12 year old operating system vulnerable and potentially out of compliance in many organisations around t…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now