Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi all,
The following code displays a list of programs installed on a machine.
please can someone explain to me what each section of the code does, I have a vague idea but need clarification !!
I would also like to know each item can be put in coma separated format so that when you open the file with excel it populated the first row with each entry in its own column, this is so I could import the data into a SQL database.
@echo off
If Exist c:\installedprogs.txt Del c:\installedprogs.txt
regedit /e c:\regexport.txt "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall"
find "DisplayName" c:\regexport.txt >c:\regprogs.txt
for /f "tokens=2 delims==" %%a in (c:\regprogs.txt) do echo %%~a >>c:\installedprogs.txt
del c:\regexport.txt
del c:\regprogs.txtexit
thanks

I have no idea how it works, but it clearly does. I changed some file names to avoid the LFN mess. I think you'll get the idea. The subroutine :sub1 builds your CSV.
Good luck
::== i5.bat
@echo offregedit /e export "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall"
find "DisplayName" export > regprogs
for /f "tokens=2 delims==" %%a in (regprogs) do (
echo %%~a >> installd
)for /f "tokens=*" %%L in (installd) do (
call :sub1 %%L
)goto :eof
:sub1
>> my.csv echo %1,%2,%3,%4,%5,%6,%7,%8,%9
:: DONE
=====================================
If at first you don't succeed, you're about average.M2

In the registry you have information of all programs installed. This is used for the Add/Remove programs function that you can find in the control panel.
This line exports the registry to a file called regexport.txt
regedit /e c:\regexport.txtNow since you dont want all of the registry, but only the programs located in the Uninstall part of the registry (that would be installed programs) you use the reg export with the string:
"HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall"
Now, this part of the registry contains lots of non useful information (For you that is). You only want the names of the program installed. This is done with:
find "DisplayName" c:\regexport.txt >c:\regprogs.txtIt prints only the lines where the DisplayName string is found (which is the programs name) to a new file regprogs.txt
Then you have the FOR command. If you open reprogs.txt you will see that it looks something like this:
"DisplayName"="ActivePerl 5.8.8 Build 817"
"DisplayName"="WinRAR archiver"
...Now, you only want the names of the programs, not the entire strings. The delimiter is set to =" and using tokens=2 will leave out "DisplayName"="
So, you should be left with the useful info only.for /f "tokens=2 delims==" %%a in (c:\regprogs.txt) do echo %%~a >>c:\installedprogs.txt
The FOR command is a command that does an operation FOR every line in a txt file (the easy explanation). So, hope this helped.I see M2 already has provided you with the code to make a comma delimited list:)

hi, thanks for both responses... excellent ! but for the CSV file i only got one line which was the first program installed.
heres what i input
@echo off
If Exist c:\installedprogs.txt Del c:\installedprogs.txt
regedit /e c:\regexport.txt "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall"
find "DisplayName" c:\regexport.txt >c:\regprogs.txt
for /f "tokens=2 delims==" %%a in (c:\regprogs.txt) do echo %%~a >>c:\installedprogs.txt
)
for /f "tokens=*" %%L in (c:\installedprogs.txt) do (
call :sub1 %%L
)goto :eof
:sub1
>> installed-programs.csv echo %1,%2,%3,%4,%5,%6,%7,%8,%9
del c:\regexport.txt
del c:\regprogs.txtexit

Hi Shr0Om,
Nice job on the explanation.
The one thing I can't figure is how, or why the %%~a gets rid of the " Any clue?
While I've got you on the horn, DDDG [different day different garbage], what's up with this
?More to the point, how to get rid of it?
I blocked similar crap months ago by putting intellitext in HOSTS.
Moving right along.
midlands, I pasted your script and got the whole enchilada. I don't know why you're getting only one line.
Try disabling the DEL lines and look at the installedprogs.txt and see what's in it.
=====================================
If at first you don't succeed, you're about average.M2

Hehe..
M2:
I dunno actually, im not quite grasping your code.. :P">> installed-programs.csv echo %1,%2,%3,%4,%5,%6,%7,%8,%9". What does %1,%2.. contains? And why only single % and not %%?
And i didnt know you could pass on variables like this "call :sub1 %%L"
So, i learnt something new:)I tried Midlands script, which only gave me one line aswell. Then i tried yours, which give me all the lines, so Midland, without going in depth of your code, something must be wrong there.. :)
M2:
Still.. The output i get is like:Notepad++,,,,,,,,
Oracle,JInitiator,1.1.8.19,,,,,,
Inte(R),PRO,Ethernet,Adapter,and,Software,,,I guess your script just replaces space with a comma, which isnt really the way to go.
Now, im guessing it should look more like this:
Notepad++;Oracle,JInitiator1.1.8.19;Intel(R)PRO Ethernet Adapter and Software;That would be, get all programs listed in one long line delimited with a comma, thus removing the EOF.
Midland: Am i on the right track?

Hi Shr0Om,
When you CALL a sub, just like CALLing a BAT and pass it a string [like %%L=the quick brown fox] it sees the first parameter, %1, as the.
second parameter ,%2, as quick
and so on
So as you figured, the :sub1 puts commas after each param.
I don't THINK OP wants everything on one line. That would seem to be a pretty useless spreadsheet.
=====================================
If at first you don't succeed, you're about average.M2

Hi M2
Ah, thats how it goes:)
I wrote before i thought, hehe. (and i was still on my 1'st cup of coffe). Ye, a one line delimited string wouldnt be much of use in this case.
But why the need of comma delimiters?
Isn't it possible to import a list looking like this into sql?Winamp
Media Player
Kaspersky Antivirus v.xx
..I dont see the point of splitting a program list into tables like this:
Inte(R),PRO,Ethernet,Adapter,and,Software,,,Could be useful for other things tho..

I don't know the first thing about SQL.
But for excel a CSV is dead easy.
===========
I still don't know why you and he are getting one line. I took out the c:\ to keep from messing with the root [never a good idea] but I'd be astonished if that made any diggerence.
=====================================
If at first you don't succeed, you're about average.M2

M2: Yeah, i wrote lots of batch scripts for converting different txt files into csv files for use in excel.
When it comes to the "oneliner" its nutting wrong with your code but in midlands11 code!
As you can see he added some unfortunate lines of code under sub1:
::---CODE---
:sub1
>> installed-programs.csv echo %1,%2,%3,%4,%5,%6,%7,%8,%9del c:\regexport.txt
del c:\regprogs.txtexit <--- This aint so good:)
::---CODE---So when sub1 is called it exits, thus only one line is written.
Dunno if there is a way around this.
I tried inserting ( ) around the :sub1 code, but that didnt help much..

Hi Shroom,
Good work.
The way to fix it is to end the loop after the "working line".
::=============
>> installed-programs.csv echo %1,%2,%3,%4,%5,%6,%7,%8,%9
goto :eof
::=============
=====================================
If at first you don't succeed, you're about average.M2

They need to go after the last FOR.
=====================================
If at first you don't succeed, you're about average.M2

I tried that, but goto :eof skips all so..
Here's the snippet i used.::---CODE---
:sub1
>> installed-programs.csv echo %1,%2,%3,%4,%5,%6,%7,%8,%9
goto eofdel c:\regexport.txt
del c:\regprogs.txt
::---CODE---Also, since i have you here..
When using the:
for /f %%i in (somefile.txt) do echo %%i >>newfile.txtand the strings in the txt file contains spaces (like filenames), only the part before the space will get written to newfile.txt
Do you know some easy workaround so the entire string will be echoed?
(Ive done some workarounds, but they arent so pretty).

for /f "tokens=*" %%i in (somefile.txt) do echo %%i >>newfile.txt
Here's the cleaned up bat:
::== inst2csv.bat
@echo off > installed-programs.csvregedit /e regexport.txt "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall"
find "DisplayName" < regexport.txt > regprogs.txt
for /f "tokens=2 delims==" %%a in (regprogs.txt) do (
echo %%~a >>installedprogs.txt )
for /f "tokens=*" %%L in (installedprogs.txt) do (
call :sub1 %%L )
del regexport.txt
del regprogs.txt
del installedprogs.txt
goto :eof
:sub1
>> installed-programs.csv echo %1,%2,%3,%4,%5,%6,%7,%8,%9
::== DONE
=====================================
If at first you don't succeed, you're about average.M2

check your PM
=====================================
If at first you don't succeed, you're about average.M2

![]() |
Batch File Help Pls
|
mortgage calculator
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |