I’ve tried this every way but Sunday and maybe someone can provide some guidance (or at least a “it doesn’t work, stop trying”).
I have a custom property that checks for presence of a specific file. The path to this file may change and is found in a specific registry key. Can I combine the local registry key value in the if-then-else statement for the custom property? I believe I can but am having difficulties doing so. Here is what I have:
Custom Property:
if (exists file “C:\Program Files\path_to_file\test.txt”) and (preceding text of first “” of line whose (line number of it = 1) of file “C:\Program Files\path_to_file\test.txt” as string) = “.” then “Yes” else “No”
The “C:\Program Files\path_to_file” is found in registry lets say key “Install_Path” within “HKEY_LOCAL_MACHINE\SOFTWARE\Product”.
I am doing this out of memory here so it’s off but basically what I have is:
if (exists file “(value “Install_Path” of key “HKEY_LOCAL_MACHINE\SOFTWARE\Product” of native registry as string & “\test.txt”)” and (preceding text of first “” of line whose (line number of it = 1) of file “(value “Install_Path” of key “HKEY_LOCAL_MACHINE\SOFTWARE\Product” of native registry as string & “\test.txt”)” = “.” then “Yes” else “No”
But doesn’t work. I know it’s a matter of " and (), etc.
Feels like I am chasing something that isn’t possible - can anyone comment as to if they feel it’s at least possible to do? Shouldn’t be any reason why not, I don’t think.
I don’t mind putting the time in to figure out the syntax
One thing I noticed that is immediately wrong is that you have mismatch quotes and parenthesis. For example, you don’t have a closing parenthesis for your if-statement and the preceding-clause. Additionally, you quoted an expression in: if(exists file “”… The relevance debugger treat everything in quotes as a string, so it will not evaluate it.
So fixing your parenthesis and quotations, the final relevance should be something like this:
if (exists file (value “Install_Path” of key “HKEY_LOCAL_MACHINE\SOFTWARE\Product” of native registry as string & “\test.txt”) and (preceding text of first “” of line whose (line number of it = 1) of file (value “Install_Path” of key “HKEY_LOCAL_MACHINE\SOFTWARE\Product” of native registry as string & “\test.txt”) = “.”)) then “Yes” else “No”
Much appreciated! Yes, I was doing it out of memory at the time (not on the same computer) and so it was farther off than in practice. But still not close enough
I will take a look at what you have, I do appreciate your time - since it’s possible to do I will redouble my efforts.
If you are struggling and want help, it is much easier for the rest of us to take a working sample (one that at least parses correctly, if not ‘working’) rather than you typing out what you think you were trying.
But as you certainly seem to have tried to work out the solution, I can appreciate that sometimes frustration can also lead to mistakes (or certainly leading to changing parts that might have worked, ad infinitum). I was going to comment on the extra "'s as well, but as that was already mentioned previously, I’ll just move on with the solution.
I set up a registry key with the value of “Install_Path” having the path to a file I knew existed. The file is called test.txt and contains “.\this\folder\file.txt” as it’s first line.
I re-wrote what I think you meant to do and it works for me.
Q: if ( exists file (value “Install_Path” of key “HKLM\SOFTWARE\Bigfix\EnterpriseClient\Settings\Client\Test” of x32 registry as string & “\test.txt”) AND (preceding text of first “” of line whose (line number of it = 1) of file (value “Install_Path” of key “HKLM\SOFTWARE\Bigfix\EnterpriseClient\Settings\Client\Test” of x32 registry as string & “\test.txt”)) = “.” ) then “Yes” else “No”
A: Yes
Make sure you want to use native registry, and not just ‘registry’ or ‘x32 registry’, etc., depending on where the key is going to end up on the different types of oses.
Lastly, you could ignore the whole preceding “if” and the following " then yes else no" part of the logic, if you were happy with the resulting (boolean) True or False. Sometimes this is also an easier result to end up with, as you can easly put it into the relevance for a task as it’s written.
Thank you Jim! I do agree with you and shouldn’t have started the thread without more specifics.
Am back on the project now and will give it a go - will report back once I have more.
Thanks again folks.
~Jason
jwilkinson
Jason,
If you are struggling and want help, it is much easier for the rest of us to take a working sample (one that at least parses correctly, if not ‘working’) rather than you typing out what you think you were trying.
But as you certainly seem to have tried to work out the solution, I can appreciate that sometimes frustration can also lead to mistakes (or certainly leading to changing parts that might have worked, ad infinitum). I was going to comment on the extra "'s as well, but as that was already mentioned previously, I’ll just move on with the solution.
I set up a registry key with the value of “Install_Path” having the path to a file I knew existed. The file is called test.txt and contains “.\this\folder\file.txt” as it’s first line.
I re-wrote what I think you meant to do and it works for me.
Q: if ( exists file (value “Install_Path” of key “HKLM\SOFTWARE\Bigfix\EnterpriseClient\Settings\Client\Test” of x32 registry as string & “\test.txt”) AND (preceding text of first “” of line whose (line number of it = 1) of file (value “Install_Path” of key “HKLM\SOFTWARE\Bigfix\EnterpriseClient\Settings\Client\Test” of x32 registry as string & “\test.txt”)) = “.” ) then “Yes” else "No"
A: Yes
Make sure you want to use native registry, and not just ‘registry’ or ‘x32 registry’, etc., depending on where the key is going to end up on the different types of oses.
Lastly, you could ignore the whole preceding “if” and the following " then yes else no" part of the logic, if you were happy with the resulting (boolean) True or False. Sometimes this is also an easier result to end up with, as you can easly put it into the relevance for a task as it’s written.