Computing.Net > Forums > Programming > View installed progs with .bat file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

View installed progs with .bat file

Reply to Message Icon

Name: midlands11
Date: July 19, 2006 at 04:15:13 Pacific
OS: XP pro
CPU/Ram: n/a
Product: n/a
Comment:

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.txt

exit

thanks




Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: July 19, 2006 at 05:18:52 Pacific
Reply:

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 off

regedit /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



0

Response Number 2
Name: Shr0Om
Date: July 19, 2006 at 06:22:55 Pacific
Reply:

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.txt

Now 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.txt

It 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:)


0

Response Number 3
Name: midlands11
Date: July 19, 2006 at 07:37:24 Pacific
Reply:

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.txt

exit


0

Response Number 4
Name: Mechanix2Go
Date: July 19, 2006 at 20:23:16 Pacific
Reply:

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



0

Response Number 5
Name: Shr0Om
Date: July 20, 2006 at 00:25:51 Pacific
Reply:

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?


0

Related Posts

See More



Response Number 6
Name: Mechanix2Go
Date: July 20, 2006 at 00:54:41 Pacific
Reply:

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



0

Response Number 7
Name: Shr0Om
Date: July 20, 2006 at 01:39:08 Pacific
Reply:

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..


0

Response Number 8
Name: Mechanix2Go
Date: July 20, 2006 at 02:16:20 Pacific
Reply:

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



0

Response Number 9
Name: Shr0Om
Date: July 20, 2006 at 02:53:24 Pacific
Reply:

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,%9

del c:\regexport.txt
del c:\regprogs.txt

exit <--- 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..



0

Response Number 10
Name: Mechanix2Go
Date: July 20, 2006 at 03:40:04 Pacific
Reply:

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



0

Response Number 11
Name: Shr0Om
Date: July 20, 2006 at 03:54:30 Pacific
Reply:

But then theese lines wont be executed:

del c:\regexport.txt
del c:\regprogs.txt



0

Response Number 12
Name: Mechanix2Go
Date: July 20, 2006 at 04:06:37 Pacific
Reply:

They need to go after the last FOR.


=====================================
If at first you don't succeed, you're about average.

M2



0

Response Number 13
Name: Shr0Om
Date: July 20, 2006 at 04:15:07 Pacific
Reply:

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 eof

del 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.txt

and 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).


0

Response Number 14
Name: Mechanix2Go
Date: July 20, 2006 at 05:12:59 Pacific
Reply:

for /f "tokens=*" %%i in (somefile.txt) do echo %%i >>newfile.txt

Here's the cleaned up bat:

::== inst2csv.bat
@echo off > installed-programs.csv

regedit /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



0

Response Number 15
Name: Shr0Om
Date: July 20, 2006 at 05:42:52 Pacific
Reply:

Ahh.. Thnx M2 :]


0

Response Number 16
Name: Mechanix2Go
Date: July 20, 2006 at 05:45:30 Pacific
Reply:

check your PM


=====================================
If at first you don't succeed, you're about average.

M2



0

Sponsored Link
Ads by Google
Reply to Message Icon

Batch File Help Pls mortgage calculator



Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: View installed progs with .bat file

Help with Bat File www.computing.net/answers/programming/help-with-bat-file/18815.html

I need help with bat file - please help www.computing.net/answers/programming/i-need-help-with-bat-file-please-help/2971.html

Help with bat file www.computing.net/answers/programming/help-with-bat-file/12224.html