Update 14/02/2017: It turns out that there is also a requirement to wait until a registry value exists and contains a particular piece of data. For this reason the script has been updated to include this functionality. The updated script is available below.
When creating a login script, application pre-launch script or even building an AppSense Environment Manager configuration you may need to wait for a file or registry value to be present. Very often a simple one-off check isn’t enough; I’ve seen environment variables get created really late in the login process so checking at the beginning of a login script might be too early.
What you need to do though is stay as deterministic as you can about these things. With a login script you can use this loop in order to halt until the registry value or file does exist. With EM you’ll be able to run this in parallel with your other tasks that aren’t dependant on that particular item.
If using this in Environment Manager you’ll probably want to make sure that you exit with
1 depending on whether the loop timed out or not (
$var will not be set or
$false on timeout).
Well, it needs no other introduction…