Issue Creating Custome Analysis

(imported topic written by SmearODeer91)

All,

While Making a custom analysis I wanted to Check for Existance of a key IF it existed THEN I wanted to pull a value I have not been able to get it to work as a full Statement.

This Works

exist key “HKEY_LOCAL_MACHINE\SOFTWARE\IBM\ADSM\CurrentVersion\Api” of registry

And This Works but will Error if it does not exist hence the logic.

value “Path” of key “HKEY_LOCAL_MACHINE\SOFTWARE\IBM\ADSM\CurrentVersion\Api” of registry as string & “\apienu.dll”

My Attempted Relevance for this part of Analysis which fails

q: if (exist key “HKEY_LOCAL_MACHINE\SOFTWARE\IBM\ADSM\CurrentVersion\Api” of registry) then (version of file (value “Path” of key “HKEY_LOCAL_MACHINE\SOFTWARE\IBM\ADSM\CurrentVersion\Api” of registry as string & “\apienu.dll”))

E: This expression could not be parsed.

Any Thoughts? :confused:

(imported comment written by SystemAdmin)

We are not completely upgraded to BES 6.0 here, but I believe you are missing the “else” part of your statement. Also if you will have to cast your version as a string if your “else” statement is going to result in a string. Something like this:

q:if (exist key “HKEY_LOCAL_MACHINE\SOFTWARE\IBM\ADSM\CurrentVersion\Api” of registry) then (version of file (value “Path” of key “HKEY_LOCAL_MACHINE\SOFTWARE\IBM\ADSM\CurrentVersion\Api” of registry as string & “\apienu.dll”)as string) else “N/A”

A: N/A

I: singular string

Hope it helps out!

(imported comment written by brolly3391)

Hello and welcome SmearODeer,

You have the right idea.

In relevance, if there is an IF and a THEN then there must be an ELSE or else you get an error. Goodness that was fun to write.

if () then () else()

Also, the return type in the THEN must match the return type in the ELSE. That is why I added in that

as string

, so that my THEN and ELSE both returned strings.

q: if (exist key “HKEY_LOCAL_MACHINE\SOFTWARE\IBM\ADSM\CurrentVersion\Api” of registry) then (version of file (value “Path” of key “HKEY_LOCAL_MACHINE\SOFTWARE\IBM\ADSM\CurrentVersion\Api” of registry as string & “\apienu.dll”)) +as string + else (“My Error Message”)

Now that we have the syntax sorted out, let’s look at the logic. If the key exists then pull the version of the file at the path contained in the key. That catches one error condition. What if the registry key exists but the value “Path” does not. Or if the Key and value are both present but the file is missing? These are all alternate error scenarios that we should try to trap.

You can do it using order of processing like this:

q: if (exists key “HKEY_LOCAL_MACHINE\SOFTWARE\IBM\ADSM\CurrentVersion\Api” of registry AND exists value “path” of key “HKEY_LOCAL_MACHINE\SOFTWARE\IBM\ADSM\CurrentVersion\Api” of registry AND exists file (value “path” of key “HKEY_LOCAL_MACHINE\SOFTWARE\IBM\ADSM\CurrentVersion\Api” of registry as string & “\apienu.dll”)) then (version of file “apienu.dll” of folder (value “Path” of key “HKEY_LOCAL_MACHINE\SOFTWARE\IBM\ADSM\CurrentVersion\Api” of registry as string)) as string else (“Registry key or value or file is missing”)

Or you could use the more advanced WHOSE clause. This is how I would write it:

q: if (exists key “HKEY_LOCAL_MACHINE\SOFTWARE\IBM\ADSM\CurrentVersion\Api” whose (exists value “Path” whose (exist folder (it as string) whose (exists file “apienu.dll” of it)) of it) of registry) then (version of file “apienu.dll” of folder (value “Path” of key “HKEY_LOCAL_MACHINE\SOFTWARE\IBM\ADSM\CurrentVersion\Api” of registry as string)) as string else (“Registry key or value or file is missing”)

Cheers,

Brolly

(imported comment written by SmearODeer91)

Thanks Brolly.

On a Side Note the Else Error mentioned was recieved, however I Did not copy and paste far enough (Sorry) But I Will Give some of this a try and See what I Get. Your Statement on Whose was not working for me but I see where I was Making the mistakes on statement.

I Settled on this relevance for final Prod use (Since it was based onthe same events that make an upgrade relevenat) which allowed me to pull another analysis.

if (exists key “HKEY_LOCAL_MACHINE\SOFTWARE\IBM\ADSM\CurrentVersion\Api” whose (exists value “Path” whose (exist folder (it as string) whose (exists file “apienu.dll” of it)) of it) of registry) then (version of file “apienu.dll” of folder (value “Path” of key “HKEY_LOCAL_MACHINE\SOFTWARE\IBM\ADSM\CurrentVersion\Api” of registry as string)) as string else (“Not Installed”)