Page 1 of 1 1
Topic Options
#159863 - 2006-03-27 08:20 PM Check registry for installed application
cuzfu Offline
Lurker

Registered: 2005-08-14
Posts: 2
Im a trying to create a script that checks to see it a particular version of software is installed. If it is not up to date then it installs the program.

I am having some trouble listing the registry key's in the uninstall hive. here is my code


$Version = "10.19"

Dim $UninstallKey, $AppKey, $KeyIndex, $Key, $Keys, $KeyExist
$KeyExist = 0
$UninstallKey = 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall'
$KeyIndex=0

While @ERROR = 0
$AppKey = EnumKey($UninstallKey, $KeyIndex)
$KeyIndex = $KeyIndex + 1
$Keys = $Keys + $UninstallKey + '\' + $AppKey

$rc = RedirectOutput("test.log",overwrite)
If @ERROR = 0
"Name found: $AppKey"?
Endif

While $KeyExist = 0
$ValueName = ENUMVALUE ($Keys, $Index)
$KeyExist = KeyExist("$AppKey + $ValueName")
$Index = $Index + 1

If $KeyExist = 0
"$AppKey: $ValueName"?

EndIf
Loop
Loop

Top
#159864 - 2006-03-27 09:17 PM Re: Check registry for installed application
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
Hello and Welcome to the board.

A couple things.

1. Please post your code within the board CODE TAGS to preserve your formatting which makes it much easier for others to read your code.

2. I don't see where you're checking for any specific software. If you know the name of the software then why are you attempting to enumerate everything?

What application are you checking for?

further basic reading of your code without checking / testing validity.

$rc = RedirectOutput("test.log",overwrite)
That is not how to use RedirectOutPut
$rc = RedirectOutput("test.log",1) to overwrite
$rc = RedirectOutput("test.log",0) append data

I would not use VARS in strings.
Generally speaking some feel it is harder to use that way, but in the long
run it will help you to code better code and find errors in your code faster on your own.

Here is an example of code I normally put in most of my scripts.
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On')
$SO=SetOption('NoMacrosInStrings','On')

As for enumerating a key structure I'd probably go with the UDF by Jens
named ArrayEnumKey

Please see my signature for links to mirrors that sort all the UDF files in an easy format to find and copy.


Edited by NTDOC (2006-03-27 09:28 PM)

Top
#159865 - 2006-03-27 09:34 PM Re: Check registry for installed application
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
Here is an example of enumerating the registry from the EXAMPLES forum.

List Registry Startup Items
http://www.kixtart.org/ubbthreads/showflat.php?Cat=0&Number=128123

Top
#159866 - 2006-03-27 11:03 PM Re: Check registry for installed application
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Cuzfu,

Your script runs in loop that never stops and only finds the first key.
I put together a script that might be helpful in your case. Be aware that I did not test the script and it needs to be changed to the proper keys it should check. I used the Office 2003 key just as an example.

Something like this might work for you.

Code:

;Break on gives the ability to end the script and not get logged off.
Break on
;
;Set the required version.
$Version = "10.19"
;
;Open the logfile, if it does not exist create it.
$rc = Open (1, "c:\log.txt", 5)
;
;This is the key for MS Office 2003 Pro.
$key = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
$app = "{90110409-6000-11D3-8CFE-0150048383C9}"
;
;Check if the app is installed.
$keyexists = KeyExist($key + $app)
If $keyexists <> "0"
;Find the displayname and the display version.
$dispname = ReadValue($key + $app, "Displayname")
$dispversion = ReadValue($key + $app, "Displayversion")
;Write name and version to the logfile.
WriteLine(1, "Application: " + $dispname + " version: " + $dispversion + " is installed." + @CRLF)
$version is SubStr($version, 1, 5)
If $version <> "10.19"
WriteLine(1, "Application: " + $dispname + " update required." + @CRLF)
;Start upadte
Run "pathtoupdatefile\update.exe"
Else
WriteLine(1, "Application: " + $dispname + " update NOT required." + @CRLF)
EndIf
Else
WriteLine(1, "Application: " + $app + " is NOT installed." + @CRLF)
EndIf
;
;Close the logfile.
$rc = Close(1)



Edited by Mart (2006-03-28 09:13 AM)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 811 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.124 seconds in which 0.098 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org