WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: mks on March 19, 2015, 07:14:50 AM

Title: List of Application on remote 2003 server
Post by: mks on March 19, 2015, 07:14:50 AM
How can I get a list of installed applications on a remote 2003 server?

I have tried this code but it is blank output.

computername = "\\%compname%" ;for REMOTE COMPUTER
string="WindowsInstaller" 
topkey=@REGMACHINE      ; start at HKEY_CURRENT_USER

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


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

retall=rRegSearch(handle,topsub,teststring,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)
Title: Re: List of Application on remote 2003 server
Post by: td on March 19, 2015, 08:26:20 AM
You aren't suppressing errors by any chance?  I copied your script snippet into WinBatch Studio, added the line

AddExtender("WWREG34I.DLL",0,"WWREG64I.DLL")

and place  the name of a local Windows 2003 server in the 'computername' variable sans the unnecessary substitution.

The script returned all the registry entries under the 'Uninstall' key.

In order for your script to work, the targeted server needs to have the remote registry and RPC services running, and the associated ports allowed through the machine's firewall.  However, the RegConnect function will usually error if it can't connect to the remote machine.  Hence the question regarding error suppression.
Title: Re: List of Application on remote 2003 server
Post by: td on March 19, 2015, 08:54:42 AM
Another common issue with RegConnect involves connecting the remote system with proper credentials.  The following Tech Database article explains how this can be done:

http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WinBatch/Registry+Connecting~to~a~Registry~on~a~Remote~Computer.txt (http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WinBatch/Registry+Connecting~to~a~Registry~on~a~Remote~Computer.txt)
Title: Re: List of Application on remote 2003 server
Post by: mks on March 19, 2015, 09:56:07 AM
Not sure what is going on yet. 

I do not have the  AddExtender("WWREG34I.DLL",0,"WWREG64I.DLL") in my code and when I do add that I get an error. I have other regconnect within the same script that are working just fine. If I do the same thing in powershell I get a list of apps, it works fine.
Title: Re: List of Application on remote 2003 server
Post by: td on March 19, 2015, 11:09:45 AM
If you are not using AddExtender at all then there is absolutely no way that your script will ever work as written.  You need to make sure you have the extender downloaded, installed on you system and loaded via AddExtender.

The 'rRegSearch' function is a function implemented in the Reggie extender.  If you don't use the AddExtender function to add the WWREG34I.DLL extender, the function is not available to your script.  If the AddExtender functions is only producing an error when you use it when both the 32-bit and the 64-bit extender are indicated  then  you are using an old version of WinBatch and/or an old version of the extender. 

If you are using an old version of WinBatch you need to remove the last two parameters from your AddExtender call.  If you are using an old version of the extender you need to upgrade to the latest version of the extender.  The previous versions of the extender had several ugly bugs that could cause strange behavior on large data sets like the one you will likely getting from your search.

Title: Re: List of Application on remote 2003 server
Post by: mks on March 20, 2015, 06:31:19 AM
I do have the extender in the script. I was running an older version 2008 I think but I did upgrade to the 2015 version but still have no luck. 

retall=rRegSearch(handle,topsub,string,looktype,lookat,dosubtree) returns this below.

\{5A5F45AE-0250-4C34-9D89-F10BDDEE665F}[WindowsInstaller]@TABSOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{710f4c1c-cc18-4c49-8cbf-51240c89a1a2}[WindowsInstaller]@TABSOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{73F3D5C5-5A7E-48F0-999E-8BBBACAFA676}[WindowsInstaller]@TABSOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{77DCDCE3-2DED-62F3-8154-05E745472D07}[WindowsInstaller]@TABSOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{7E8833A1-AF24-4CAE-82DF-CFE14C14B94D}[WindowsInstaller]@TABSOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{86CE85E6-DBAC-3FFD-B977-E4B79F83C909}[WindowsInstaller]@TABSOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{90A40409-6000-11D3-8CFE-0150048383C9}[WindowsInstaller]@TABSOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{949F1167-A591-4DFE-944A-8D1FC68896D4}[WindowsInstaller]@TABSOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{9A25302D-30C0-39D9-BD6F-21E6EC160475}[WindowsInstaller]@TABSOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{9BE518E6-ECC6-35A9-88E4-87755C07200F}[WindowsInstaller]@TABSOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-7AD7-1033-7B44-AA1000000001}[WindowsInstaller]@TABSOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{B55FEFEC-8FCC-4A16-B3CB-41673BA5545B}[WindowsInstaller]@TABSOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{C25EF637-BE7A-4761-9B45-9069989C319F}[WindowsInstaller]@TABSOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{C3F7F88E-4BC8-4926-B153-3026B3432C18}[WindowsInstaller]@TABSOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{CAE7D1D9-3794-4169-B4DD-964ADBC534EE}[WindowsInstaller]@TABSOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{D7B169BD-D8BF-4520-B519-81F85AD91843}[WindowsInstaller]@TABSOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{DD6F02CF-6A33-4CDE-AA82-CE3B37359171}[WindowsInstaller]@TABSOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{E7D4E834-93EB-351F-B8FB-82CDAE623003}[WindowsInstaller]@TABSOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{EE8CFFD9-6E29-4DC3-A967-7348D5F41F44}[WindowsInstaller]


The item count find 33 listed.  The Keypath = ItemExtract Returns this,

SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{00203668-8170-44A0-BE44-B632FA4D780F}[WindowsInstaller]


but I still get blank output.
Title: Re: List of Application on remote 2003 server
Post by: td on March 20, 2015, 06:36:31 AM
I was referring to upgrading the extender and not WinBatch. Although, WinBatch some very significant improvements since the 2008 version and I think you will notice the difference.

You claim to be getting blank output and yet you show that the rRegSearch function is producing results.  Both cannot be the case.   

When I run your script as posted against a remote Windows 2003 server I get content that looks like the following

SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\AboutTime_is1[DisplayName]@TabSOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\AboutTime_is1[DisplayName]...

Perhaps when you say 'blank' you mean that you were expecting to get the data contents of the registry value but that is not how rRegSearch works.  As the help file states, the functions returns the "Matching Subkeys and Value Names".  In other words, it returns registry paths but not the data content of those paths.  You will need to call the RegQueryValue function on each returned registry path.  For example, to get the display name of the first item in the list would look something like the following in the context of your script:

Code (winbatch) Select
strValue = RegQueryValue(handle,ItemExtract(1, retall, @Tab))

But the above will not work if you are not getting the value name you want in each item of your return list. I get the  [Displayname] value name in each item of the return list when using your script with the latest version of the extender and the RegQueryValue function returns the contents of the value [Displayname].

33 returned items seems a bit off.  I suppose it is possible but I get 378 items in the return list on a system with very little installed software.  So, again, go to the download page and check the version number of the current version of the extender against the version you are using. 
Title: Re: List of Application on remote 2003 server
Post by: mks on March 20, 2015, 06:51:41 AM
I am now using, AddExtender("WWREG34I.DLL",0,"WWREG64I.DLL").
Title: Re: List of Application on remote 2003 server
Post by: mks on March 20, 2015, 08:37:41 AM
I do have,

name = RegQueryValue(handle,newkey)

But when I never get to that line of code. It gets to,

if RegExistValue(handle,newkey)

Then it skips to the endif and moves on to the next one. So it pulls a list of keys, (and you are right 33 seems small) but it seems like the keys it is pulling is not what is on that server. Even though it is setup like below to pull from said server.

computername = "\\server01" ;for REMOTE COMPUTER
string="WindowsInstaller" 
topkey=@REGMACHINE      ; start at HKEY_CURRENT_USER

topsub="SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
handle = RegConnect(computername, topkey)
Title: Re: List of Application on remote 2003 server
Post by: td on March 20, 2015, 11:04:13 AM
 You have still not stated which version of the extender you are using.  Please provide that information...

When you search for the "WindowsInstaller" value instead of the "DisplayName" you are going to get fewer returned items in your list because most installations don't set the value. 

Again taking your original script and changing the 'string' variable from "DisplayName" to "WindowsInstaller" and then adding the following:
Code (winbatch) Select

strValuePath = ItemExtract(1, retall, @Tab)
if RegExistValue(handle,strValuePath)
   Data = RegQueryValue(handle,strValuePath)
else
   Data = "Value not found"
endif


The Data variable for the first registry path in the list contains the number 1 which is an expected value since it is has the type REG_DWORD.   
Title: Re: List of Application on remote 2003 server
Post by: td on March 20, 2015, 02:31:36 PM
Your don't happen to have one of the rare 64-bit Windows 2003 servers by any chance?
Title: Re: List of Application on remote 2003 server
Post by: mks on March 26, 2015, 10:05:13 AM
No on the 64Bit and I am using version 18010

Not sure why it is not working maybe you could share your script and maybe I just have something that is typo. I wrote a VBScript and it worked fine.
Title: Re: List of Application on remote 2003 server
Post by: td on March 26, 2015, 12:09:33 PM
My script was (note the past tense) your script with the previously mentioned changes.  Post your script and we might be able to find your problem.
Title: Re: List of Application on remote 2003 server
Post by: mks on March 26, 2015, 12:37:28 PM
computername = "\\%compname%" ;for REMOTE COMPUTER
string="DisplayName" 
topkey=@REGMACHINE      ; start at HKEY_CURRENT_USER

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


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

retall=rRegSearch(handle,topsub,teststring,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)
Modify message
Title: Re: List of Application on remote 2003 server
Post by: td on March 26, 2015, 01:36:44 PM
If by 'working' you mean that the 'list' variable contains the display names of the installed applications on a remote server then your script works just fine for me on a Windows 7 x64 querying a Windows 2003 x86 server.

(using 2015A with full admin privileges)
Code (winbatch) Select

ddExtender("WWREG34I.DLL")

; Substitution and backslashes don't hurt but arn't necessary.
computername = 'ranger'
;computername = "\\%compname%" ;for REMOTE COMPUTER   
;string="DisplayName"  ??
topkey=@REGMACHINE      ; start at HKEY_CURRENT_USER

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


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

retall=rRegSearch(handle,topsub,teststring,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,keyPath)
      name = RegQueryValue(handle,keyPath)
      list = StrCat(list,@tab,name)
   endif
Next
list = StrReplace(StrTrim(list),@tab,@cr)
message("Product list",list)
Title: Re: List of Application on remote 2003 server
Post by: td on March 26, 2015, 02:03:33 PM
Don't recall you stating which version of Windows you are executing the script on nor whether or not it is 64-bit.  Both could make a difference.
Title: Re: List of Application on remote 2003 server
Post by: mks on March 27, 2015, 04:33:26 AM
Server 2003 only. Would this not work on Server 2008 as well what is the problem with 64bit and how would that be handle differently?  Right now I am working on server 2003 but in the future may need to do the same for 64bit newer OS's.  Thanks for your help!
Title: Re: List of Application on remote 2003 server
Post by: td on March 27, 2015, 06:42:18 AM
Windows 2008 and 64-bit can be handled by using the optional 'remoteOSflag' to indicate the bitness of the remote system.  However, my question is about the local system you are using to access the remote system.  Are you saying that you you are accesses a remote 2003 server from a local 2003 server?