WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Reggie

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Using WMI List Applications


Question:

I have a script that connects to a machine and then uses WMI to generate an application listing. This list is then used to either repair or uninstall a product. Problem is when I run it against my machine I get a full listing while running it against the same machine remotely gets a smaller subset of the same list. I am an admin of the device. Any ideas or direction is appreciated. Thanks.

Code Snip to generate listing

Locator = ObjectOpen("WbemScripting.SWbemLocator")
Service = Locator.ConnectServer("%Computername%")
Security = Service.Security_
Security.ImpersonationLevel = 3
Adapters = Service.InstancesOf("Win32_Product")
If LastError( ) == 1261
sComment="Error: WMI missing or not installed. %@CRLF% Utility will now exit."
Message("WMI Test:", sComment)
Exit
endif
hEnum = ObjectCollectionOpen(Adapters)
Product = ObjectCollectionNext(hEnum)
Count=0
Adapter=""
While 1
Count=Count+1 
AdapterType%Count% = Product.Name
Adapter=StrCat(Adapter,@Tab,AdapterType%Count%)
Product = ObjectCollectionNext(hEnum)
If Product==0 Then Break
EndWhile
Adapter=STRTRIM(Adapter)
Adapter=ItemSort(Adapter, @Tab)
Applist=Adapter

Answer:

Not sure. When you use the Win32_product class in WMI, maybe it only lists all the software that is deployed to the computer but cannot list the software deployed for the current user...

I was unable to recreate the problem. WMI returned the same lists whether it was run locally, or accessed remotely....

Apparently Win32_Product only gives the names of software that is installed via ".msi" files...

Maybe you could use RegConnect then enumerate the registry key HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall

User reply:

All the products in question are deliverd via group policy and are MSI packages. Problem is if the product isn't being polled then I can't perform the method call on it to uninstall/reinstall it. I know the code is ok because when run locally (calling the local machine instead of remote) it will pull all the apps correctly and I can perform the method call correctly. I'm thinking it's a flaw/limitation with MS or perhaps I'm not doing something correct to obtain the listing of products for both the computer and user. Any thoughts are appreciated...

Answer:

The only thing I can think of the suggest is to try modifying the ConnectServer line to include user name and password information:
Service = Locator.ConnectServer(computername,"root/cimv2",username,password)
That way you are absolutely sure the script is using the same user account to accesss the product information.

User reply:

Yeah I thought the same thing but got the same results. A quick check with MS and it seems that others have the same or similar results with getting the installed software listing via WMI. Just frustrating because it works beautifully when run locally, just need that final step.

Answer:

Have you considered my previous suggestion of using regConnect (Maybe you could use Reconnect then enumerate the registry key HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall )to connect to the remote machine then getting a list?

Here is some code that uses the REGGIE EXTENDER.

Note: this code was tested on WIndows Xp and Windows 2000.....

AddExtender("WWREG34I.DLL")
computername = ""; LOCAL COMPUTER 
;computername = "\\COMPUTER" ;for REMOTE COMPUTER
string="WindowsInstaller"  
topkey=@REGMACHINE      ; start at HKEY_CURRENT_USER

topsub="SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
handle = RegConnect(computername, topkey)

looktype=1              ; look at REG_SZ string values
lookat=2	              ; look for wholestring matches only, in all registry types: Keys, Values, Data
dosubtree=@FALSE        ; do not return subtree contents

retall=rRegSearch(handle,topsub,string,looktype,lookat,dosubtree)

list = ""
count=ItemCount(retall,@tab)
For xx  = 1 to count
	keypath = ItemExtract(xx,retall,@tab)
	newkey = StrReplace(keypath, string, "DisplayName")
	if RegExistValue(handle,newkey)
	   name = RegQueryValue(handle,newkey)
	   list = StrCat(list,@tab,name)
	endif
Next
list = StrReplace(StrTrim(list),@tab,@cr)
message("Product list",list)

exit

Article ID:   W15870
File Created: 2017:07:28:13:58:41
Last Updated: 2004:03:30:15:41:13