Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

"Select * from Win32_Product" Not Finding All Apps

1,351 views
Skip to first unread message

colin.s...@gmail.com

unread,
May 15, 2008, 10:06:20 AM5/15/08
to
I've written a script which uses regular expressions to search for
applications installed on a users PC (and uninstall them if
necessary). However I've just noticed its not finding all my apps.

For example if I look in Add/Remove programs in Control Panel, I can
see that I have 7-Zip installed. However if I run the script below,
it does not does not see it. Is there an alternative to "Select *
from Win32_Product" that I can run which will find everything?

TIA,

Colin


strComputer = "."

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root
\cimv2")

Set colSoftware = objWMIService.ExecQuery _
("Select * from Win32_Product")

For Each objSoftware in colSoftware
sList = sList & objSoftware.Caption & vbcr
Next

msgbox sList

Harvey Colwell

unread,
May 15, 2008, 11:19:28 AM5/15/08
to
This method will only find applications that use Microsoft's installer. They
are the only ones that get registered with WMI. There has been many posts
about how to find applications installed by other installers. Google for it.


<colin.s...@gmail.com> wrote in message
news:addff040-a101-4bbc...@d45g2000hsc.googlegroups.com...

James Whitlow

unread,
May 15, 2008, 2:57:13 PM5/15/08
to
<colin.s...@gmail.com> wrote in message
news:addff040-a101-4bbc...@d45g2000hsc.googlegroups.com...
> I've written a script which uses regular expressions to search for
> applications installed on a users PC (and uninstall them if
> necessary). However I've just noticed its not finding all my apps.
>
> For example if I look in Add/Remove programs in Control Panel, I can
> see that I have 7-Zip installed. However if I run the script below,
> it does not does not see it. Is there an alternative to "Select *
> from Win32_Product" that I can run which will find everything?
>
> TIA,
>
> Colin

You could enumerate the 'Uninstall' registry key looking for the
'DisplayName' values.

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Const HKLM = &H80000002

strComputer = "."

Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}" _
& "!\\" & strComputer & "\root\default:StdRegProv")

sPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
oReg.EnumKey HKLM, sPath, aKeys

For Each sKey in aKeys
oReg.GetStringValue HKLM, sPath & "\" & sKey, "DisplayName", sName
If Not IsNull(sName) Then sList = sList & sName & vbCr
Next

WScript.Echo sList
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

colin.s...@gmail.com

unread,
May 16, 2008, 6:57:37 AM5/16/08
to
On 15 May, 19:57, "James Whitlow" <jwhitlow.60372...@bloglines.com>
wrote:
> <colin.stead...@gmail.com> wrote in message


Thanks James. This seems work quite nicely and gives me a full
listing of installed apps.

However I've been faffing about with it and trying to get it to delete
the '7-Zip' application... and failing miserably.

I'm trying to use 'msiexec /x' (assuming I cant use WMI after reading
Harveys post) to uninstall the software by pointing it at the 7-Zip
key within "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", but
all that happens is that I get a popup window that appears to be the
'Windows Installer' help information (contents of it copied at
bottom).

I'm at a loss here, any chance you could cast a glance at the script
I've copied just below and advise how to get it to uninstall:

Thanks again.

Colin

======UNINSTALL 7-ZIP TEST=============================

Const HKLM = &H80000002

strComputer = "."

Set WshShell = CreateObject("WScript.Shell")


Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}" _
& "!\\" & strComputer & "\root\default:StdRegProv")

sPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
oReg.EnumKey HKLM, sPath, aKeys

For Each sKey in aKeys
oReg.GetStringValue HKLM, sPath & "\" & sKey, "DisplayName", sName
If Not IsNull(sName) Then

If InStr(1,sName,"7-Zip",1) then
msgbox "Key= " & sKey,,"Uninstalling " & sName
WshShell.Run "msiexec /x /passive {" & sKey & "}"
End If
End If

Next

====================================================

======WINDOWS INSTALLER WINDOW CONTENT=============

Windows ® Installer. V 3.01.4000.1823

msiexec /Option <Required Parameter> [Optional Parameter]

Install Options
</package | /i> <Product.msi>
Installs or configures a product
/a <Product.msi>
Administrative install - Installs a product on the network
/j<u|m> <Product.msi> [/t <Transform List>] [/g <Language ID>]
Advertises a product - m to all users, u to current user
</uninstall | /x> <Product.msi | ProductCode>
Uninstalls the product
Display Options
/quiet
Quiet mode, no user interaction
/passive
Unattended mode - progress bar only
/q[n|b|r|f]
Sets user interface level
n - No UI
b - Basic UI
r - Reduced UI
f - Full UI (default)
/help
Help information
Restart Options
/norestart
Do not restart after the installation is complete
/promptrestart
Prompts the user for restart if necessary
/forcerestart
Always restart the computer after installation
Logging Options
/l[i|w|e|a|r|u|c|m|o|p|v|x|+|!|*] <LogFile>
i - Status messages
w - Nonfatal warnings
e - All error messages
a - Start up of actions
r - Action-specific records
u - User requests
c - Initial UI parameters
m - Out-of-memory or fatal exit information
o - Out-of-disk-space messages
p - Terminal properties
v - Verbose output
x - Extra debugging information
+ - Append to existing log file
! - Flush each line to the log
* - Log all information, except for v and x options
/log <LogFile>
Equivalent of /l* <LogFile>
Update Options
/update <Update1.msp>[;Update2.msp]
Applies update(s)
/uninstall <PatchCodeGuid>[;Update2.msp] /package <Product.msi |
ProductCode>
Remove update(s) for a product
Repair Options
/f[p|e|c|m|s|o|d|a|u|v] <Product.msi | ProductCode>
Repairs a product
p - only if file is missing
o - if file is missing or an older version is installed (default)
e - if file is missing or an equal or older version is installed
d - if file is missing or a different version is installed
c - if file is missing or checksum does not match the calculated
value
a - forces all files to be reinstalled
u - all required user-specific registry entries (default)
m - all required computer-specific registry entries (default)
s - all existing shortcuts (default)
v - runs from source and recaches local package
Setting Public Properties
[PROPERTY=PropertyValue]

Consult the Windows ® Installer SDK for additional documentation on
the
command line syntax.

Copyright © Microsoft Corporation. All rights reserved.
Portions of this software are based in part on the work of the
Independent JPEG Group.


====================================================

.

James Whitlow

unread,
May 16, 2008, 8:58:27 AM5/16/08
to
<colin.s...@gmail.com> wrote in message
news:4bdb59a3-8776-40f5...@i76g2000hsf.googlegroups.com...

I don't have 7-Zip installed, so I cannot speak to it very well.
However, most applications in the 'Uninstall' area of the registry should
have an 'UninstallString' listed in their key. Quite often you can add (or
change) a switch to the string to have it uninstall silently. Open up
regedit.exe and navigate to
'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall' and
then search for 7-Zip and see what it's uninstall string looks like.

If you don't have any luck with the above, reply to this thread and post
the value of 7-Zip's 'UninstallString' and perhaps someone can advise the
syntax to make it uninstall silently.


mayayana

unread,
May 18, 2008, 11:45:52 PM5/18/08
to
As James Whitlow said, you want to run the UninstallString
value from the Uninstall key.
The Win32_Product WMI class is just a partial wrapper around
MSI. You can get at that directly with the
WindowsInstaller.Installer object. But if you didn't install the
program with an MSI file then Windows Installer doesn't know
about it and Windows Installer can't uninstall it.

Frankly, the whole Windows Installer system is overproduced
crap that's only used by companies that want to cooperate
closely with Microsoft. A great deal of 3rd-party software,
and most older software, is NOT packaged as an MSI. So unless
you're dealing only with one specific, known program you need
to go though the Registry, like the Add/Remove applet does.


colin.s...@gmail.com

unread,
May 19, 2008, 10:25:22 AM5/19/08
to


Hi Mayayana/James,

Thankyou for your input.

I have found the uninstall keys as pointed out by James (thanks
James).

Mayayana can I use these 'uninstall' strings to silently uninstall
applications outside of WMI? Is that what you were referring too by
"go(ing) though the Registry, like the Add/Remove applet does"? If so
could you point me in the right direction for achieving that? I'm a
bit out of my depth here and I'm not sure how to use these uninstall
strings.

7-Zip is just an app I'm picking on for testing purposes as its a
quick job to reinstall it if need be. But there is a whole series of
apps that I'm trying to uninstall (Winrar, Powerdvd, Nero, Mcafee,
Photoshop, Paintshop, Winzip... with plenty of others to follow), and
some of them appear not to have been installed by the Windows MSI. So
as it stands my script isn't looking too great at the moment as I've
built the whole thing around WMI in the assumption it would work for
any application (after testing it with McAfee and finding that it
worked flawlessly I didn't think to try it on anything else - stupid-
arse!).

Thanks again,

Colin

mayayana

unread,
May 19, 2008, 12:22:07 PM5/19/08
to
Unfortunately the whole thing isn't very well
standardized. It's really up to the installer to
provide options for you. A given software program
can install without necessarily having an uninstall
option. (Some adware-type stuff does that.)

The basic system has been that software is supposed
to add a key to the Uninstall key. In that key should
be at least the values DisplayName and UninstallString.
The former value is used by the Add/Remove applet,
which displays the data in the Add/Remove window.
The latter value is a command string to start the uninstall.

On my system I currently have in
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\7-Zip

DisplayName: 7-Zip 4.32
UninstallString: "C:\Program Files\7-Zip\Uninstall.exe"

So if I open Add/Remove and select the 7-Zip entry
for removal it will run the uninstall.exe file.

The key names under the Uninstall key are not necessarily
meaningful. MSI uses GUIDs as key names. Some other
software uses the program name, some doesn't. So if there's
no UninstallString value you're out of luck.

It sounds like you already have the MSI versions working,
but if it were me I think I'd skip that, since it all really boils
down to the UninstallString. In other words, you can
enumerate installed MSI software with Windows Installer or
WMI, but if you still have to walk the Registry Uninstall subkeys
then you might just as well standardize your method on that,
doing it like Add/Remove does: Enumerate the subkeys, dropping
any that don't have both DisplayName and UninstallString entries.
Then search the DisplayName strings for the program you want
to uninstall, and run the UninstallString value from the same key.
That should work equally well for MSI files. For instance, the
Uninstall string value I have for the SAPI 5 SDK is this:

MsiExec.exe /I{1F76A47D-98CC-4863-822D-75C4A4DDDDB9}

You happen to be calling msiexec in the case of MSI files,
but you don't have to care about that if your script is going
through the Registry, using the UninstallString values, rather than
calling WMI or WI.

James Whitlow

unread,
May 19, 2008, 2:15:03 PM5/19/08
to
<colin.s...@gmail.com> wrote in message
news:769e6e00-28f9-4e0e...@m73g2000hsh.googlegroups.com...

As Mayayana stated, it is not very standardized. However, you should be
able to, with a little work, create a script that will silently uninstall
many (maybe most) applications. Some applications actually offer you the
silent uninstall string in the registry. For instance, on my computer,
'UltraISO' offers both an 'UninstallString' entry and a
'QuietUninstallString' entry with the only difference being '/SILENT' at the
end. If the 'QuietUninstallString' exists, use it. If not, you can read in
the uninstall string (if present) for the app from the registry and search
the string to look for known installer packages and add their quiet switch
('/qn' for MSI, '/S' for Wise, etc.) to the end. For non-standard situations
you might have to create some individual strings for those applications.
Mayayana stated that 7-Zip 4.32 has an uninstall string of "C:\Program
Files\7-Zip\Uninstall.exe". This may or may not be silent. If it is not, you
might try a few different switches to see if any of them operate silently.
Try '/S', '/Q', '/Silent' & '/Quiet'. You might also do a Google search for
the silent uninstall string. Sometime you can even execute the uninstall
command from a command line and add ' /?' to the end and get a list of
supported swtiches.


0 new messages