Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL to list all programs installed on local machine?

Status
Not open for further replies.

wz

Programmer
Feb 16, 2001
88
0
0
US
I'd like to use SQL Server 2014 Management Studio and write a SQL statement that returns all the program files on my computer - or better yet another user's computer. But first things first....your help would be appreciated.

First I'm trying to list just my machines programs that are installed along with the current version, and PK.

I found code on-line that works (although I am not sure exactly why since I don't see a \Country List\ but I do see up to the Telephony):

EXECUTE master.dbo.xp_regread
@rootkey = 'HKEY_LOCAL_MACHINE',
@key = 'SOFTWARE\Microsoft\Windows\CurrentVersion\Telephony\Country List\1',
@value_name = 'Name';
this returns answers: 14.0, common, excel, outlook, powerpoint, word

But I want something that is a listing similar to the ControlPanel, Program and Features listing: file names, publisher, installed on, version.

I tried:
EXECUTE master.dbo.xp_regread
@rootkey = 'HKEY_LOCAL_MACHINE',
@key = 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall',
@value_name = 'DisplayName';

when I run this I get the error:
RegQueryValueEx() returned error 2, 'The system cannot find the file specified.'
Msg 22001, Level 1, State 1

(0 row(s) affected)

This also worked (just not detailed enough):
EXEC master..xp_regenumkeys
'HKEY_LOCAL_MACHINE',
'SOFTWARE\Microsoft\Office'

but I want to drill down more like
EXEC master..xp_regenumkeys
'HKEY_USERS',
'SOFTWARE\Microsoft\Office\14.0\Access\File MRU'

which returns error:
Msg 22001, Level 16, State 1, Line 5
RegOpenKeyEx() returned error 2, 'The system cannot find the file specified.'
 
If you look in regedit at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
each software is in it's own key so you would need to look in that key for the display name...

in this example replace {0259C5EE-D53B-40A0-80A7-30C88D217749} with a key from your system.

declare @dir nvarchar(4000)
EXECUTE master.dbo.xp_regread
N'HKEY_LOCAL_MACHINE',
N'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{0259C5EE-D53B-40A0-80A7-30C88D217749}',
N'DisplayName',
@dir output

select @dir


Simi

 
Just a thought... if the goal is to do this on enduser computers and you see what is installed on everyone's machine. You might want to consider a batch file like

REG QUERY HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /s /f DisplayName > \\YourServer\Share\%computername%.txt

Then you could read each file on the server and put the contents into a table in the database. Then sql would not be required on each computer.

Simi

 
simian336 - Thank you for taking the time to reply.

I've run your first suggestion and I get back 'The system cannot find the file specified.' Although I've copied and pasted the exact key and it is obviously there.

EXECUTE master.dbo.xp_regread
'HKEY_LOCAL_MACHINE',
'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}';
returns the keyexist value of 0 (my x's are in place of an actual key)

I did run:
EXEC master..xp_regenumkeys
'HKEY_LOCAL_MACHINE',
'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\'

and I receive almost what I want (52 rows). However, it doesn't return all values in that dir. Nor does it return all the programs installed on the machine.

I would like to see something that is a listing similar to the ControlPanel, Program and Features listing: file names, publisher, installed on date, version.

End users (about 50 users - all different machines) use a front end Access database and we use SQL server as the backend and sometimes end users are not using the most recent install of the Access program (I remotely install updates once a year or so) and it would be so helpful if I knew up front what version they are using...thought SQL could return this similar to how I use auditing to inform me of the user login name, computer name, values that are changed, etc. If I look into the ControlPanel I see the version of this Access database - that's what I'd like SQL to return.

I'm heading away on vacation - so I'll check this forum after I return in Jan 3. Thanks again for your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top