INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

SQL to list all programs installed on local machine?

SQL to list all programs installed on local machine?

(OP)
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.'

RE: SQL to list all programs installed on local machine?

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

RE: SQL to list all programs installed on local machine?

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

RE: SQL to list all programs installed on local machine?

(OP)
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!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close