Return static string value in place of an error

(imported topic written by rmnetops91)

I have a property that returns the IE proxy settings on our machines. This works just fine, unless the user is logged off the machine, then it returns “Singular expression refers to nonexistent object.” or “” in my reports. Is there a way I can change the code below so if it errors out, it returns a static value that I define such as “No user logged on”?

if (name of operating system as lowercase starts with “win”) then if (exists value “ProxyServer” of key “SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings” of current user keys (logged on users) of registry) AND (exists key “SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings” whose (value “ProxyEnable” of it as integer = 1) of current user keys (logged on users) of registry) then (value “ProxyServer” of key “SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings” of current user keys (logged on users) of registry as string) else if (exists key “SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings” whose (exists value “AutoConfigURL” of it) of current user keys (logged on users) of registry) then "Automatic Configuration Script - " & (value “AutoConfigURL” of key “HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings” of current user keys (logged on users) of registry as string) else “Not Enabled” else “Non-Windows Install”

(imported comment written by MattBoyd)

Probably the easiest way is to just add another if statement to check if there is a user logged on:

if exists (current user) then (

if (name of operating system as lowercase starts with 
"win") then 

if (exists value 
"ProxyServer" of key 
"SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings" of current user keys (logged on users) of registry) AND (exists key 
"SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings" whose (value 
"ProxyEnable" of it as integer = 1) of current user keys (logged on users) of registry)  then (value 
"ProxyServer" of key 
"SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings" of current user keys (logged on users) of registry as string) 

else 

if (exists key 
"SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings" whose (exists value 
"AutoConfigURL" of it) of current user keys (logged on users) of registry) then 
"Automatic Configuration Script - " & (value 
"AutoConfigURL" of key 
"HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings" of current user keys (logged on users) of registry as string) 

else 
"Not Enabled" 

else 
"Non-Windows Install") 

else 
"No user logged on"

(imported comment written by rmnetops91)

That works!

Thanks