Windows IT Pro is the authoritative and independent resource for windows nt, windows 2000, windows 2003, windows xp. Features a collection of resources and magazines for windows IT professionals.
  
  
  Advanced Search 


February 12, 2004

Querying Installed Software Remotely

Perform simple software audits easily and quickly
RSS
View this exclusive article with VIP access -- click here to join |
See More Registry Articles Here | Reprints | Or sign up for our VIP Monthly Pass!

Administrators perform software audits to ensure that licensing agreements are followed, detect unauthorized software, and prepare for upgrades and migrations. To facilitate software audits, you can install a variety of third-party utilities and agents, some of which, in addition to gathering a list of installed software, can also collect information, such as the amount of free disk space, service status, and BIOS version, and even deploy software. However, at times you might want to remotely determine which software is installed on a workstation or server. The Control Panel Add/Remove Programs applet looks at one registry subkey (and its values), and you can query this subkey to display a list of installed applications. The script QueryInstalledSoftware.cmd, which Listing 1 shows, uses this querying process to easily and quickly perform a low-cost software audit.

Using Reg.exe to Query the Subkey
The HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall subkey contains the values that Add/Remove Programs uses to display a computer's installed software. You can use the reg.exe utility to remotely query this subkey. (Reg.exe used to be part of the Microsoft Windows NT 4.0 Resource Kit but now is part of Windows 2000 Support Tools.) You can also use reg.exe to locally and remotely add, delete, and update subkeys from the command line. The Uninstall subkey contains values that represent applications and contain information such as software name, installation source, and uninstall string. The displayname value contains the software name that Add/Remove Programs displays. To use reg.exe to query the subkey, you can type the following command on the command line:

Reg Query HKLM\SOFTWARE   Microsoft\Windows   CurrentVersion\Uninstall
   /S \\compname

(Although this command appears on several lines here, you would enter it on one line on the command line. The same holds true for the other multiline commands in this article.) This command outputs all the Uninstall subkey values for the specified computer (compname). Because you don't need all this output, you can massage the output to display only the displayname values. The simplest way to do this is to pipe the output of the Reg Query command to the Find command: . . .

Reader Comments
<P>The XP version of reg.exe does query the registries of remote computers. The syntax is \\computer\FullKey. Only HKLM and HKU are available on remote computers.</P>

Eric Case February 17, 2004


<P>Just FYI. The WXP vergion of REG.EXE does allow you to query remote machines. It just has a slightly different syntax. Instead of <BR>
<BR>
<DD>Reg query HKLM\.... \\%machine%<BR>
<BR>it is expecting <BR>
<BR>
<DD>Reg query \\%machine%\HKLM\....<BR>
<BR>
Same as the version that comes with W2K resource kit.</P>

Eric J. Wang February 18, 2004


<P>I keep getting the following error when I run this program: <I>Installed Software for
*machine name*. The syntax of the command is incorrect.</I> I believe the code in callout B in QueryInstalledSoftware.cmd
is in error but I just can't "see" the actual error.</P>
<P><B>A note from Steve:</B> Without more information, it's hard to tell whether there’s an error with the code or if the code was copied incorrectly. If you email me (steve@seguis.com) a copy of the script you’re using and the command you’re typing to execute the script, I should be able to find out. </P>

B. Nicholl March 05, 2004


<P>If you change the code:<BR>
<BR>
<DD>If %ERRORLEVEL% EQU 0 Echo %targetcomp% is <BR>
<DD>unavailable at this time & Goto :EOF<BR>
<BR>
to <BR>
<BR>
<DD>If %ERRORLEVEL% EQU 1 Echo %targetcomp% is <BR>
<DD>unavailable at this time & Goto :EOF <BR>
<BR>
it's going to continue the script.</P>

Gustavo Pinto March 16, 2004


<P>This is the right command-line code to get remote computer info <BR>
<BR>
<DD>For /f "tokens=1,2,*" %%i in <BR>
<DD>('Reg Query \\%targetcomp%\HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall <BR>
<DD> /S ^| Find /I "DisplayName" ^| Find /V /I "Quiet"')</P>

Gustavo Pinto March 16, 2004


for /f "tokens=*" %%a in ('reg query hklm\software\microsoft\windows\currentversion\uninstall') do (
for /f "tokens=*" %%b in ('reg query %%a /v displayname ^| find "displayname" /I') do echo "%%b")

browolf May 24, 2006 (Article Rating: )


Having made the changes noted by Gustavo, I still get a "syntax of the command is incorrect" error running the batch. However, if I run the 'Reg Query...' component on it's own at the command prompt, I get output.

I'm really not sure what's wrong!

nqetech February 28, 2008 (Article Rating: )


You must log on before posting a comment.

If you don't have a username & password, please register now.




Top Viewed ArticlesView all articles
Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

Microsoft Touts Xbox 360 'Black Friday' Success

Microsoft this week revealed that its Xbox 360 video game console outsold its Sony PlayStation 3 rival 3-to-1 on "Black Friday," which curiously describes the three day weekend after Thanksgiving, a period that unofficially kicks off the holiday selling ...

How can I stop and start services from the command line?

...


Task Automation Whitepapers Essential Guide to E-discovery and Recovery for Microsoft Exchange

Continuous Data Protection and Recovery for Microsoft Exchange

Protecting (You and) Your Data with Exchange Server 2007

Related Events How IE7 & The New Extended Validation SSL Certificates Impact Your Site

Introduction to Identity Lifecycle Manager "2"

Power Up! With Virtualization Online Conference

Check out our list of Free Email Newsletters!

Task Automation eBooks Spam Fighting and Email Security for the 21st Century

A Guide to Windows Certification and Public Keys

Keeping Your Business Safe from Attack: Patch Management

Related Task Automation Resources Become a VIP member of the Windows IT Pro community!
Get it all with the VIP CD and VIP access. A $500+ value for only $279!

Subscribe to Windows IT Pro!
Solve your toughest technical problems with our experts and access 10,000 + articles online. 30% off

Monthly Online Pass - Only $5.95!
Get instant access to 10,000+ articles from Windows IT Pro Magazine!

TechNet Virtual Labs
Evaluate and test Microsoft's newest products.


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro Windows Dev Pro IT Job Hound ITTV
IT Library Technology Resource Directory Connected Home Windows Excavator Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 Copyright © 2008 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing