Relevance for specific mapped network drive

I am trying to create a property that returns a specific mapped drive and its remote path. I have code to pull all the Network drives but I am trying to limit it specifically to one specific drive used by one application.

I started with this relevance and I am trying to pull back only the P drive.

q: if Exists(value “RemotePath” of it as string) of keys of (keys(“Network”) of Keys of key “HKEY_USERS” of registry) then (name of it & ": " & value “RemotePath” of it as string) of keys of (keys(“Network”) of Keys of key “HKEY_USERS” of registry) else "Network Drive Not Found"
A: O: \SERVER\SHARE
A: P: \SERVER\SHARE
T: 1.768 ms

I tried by adding string contains and selecting the specific drive but I am getting incompatible types

q: if Exists(name of it as string contains “P”) of keys of (keys(“Network”) of Keys of key “HKEY_USERS” of registry) then (name of it & ": " & value “RemotePath” of it as string contains “P”) of keys of (keys(“Network”) of Keys of key “HKEY_USERS” of registry) else "P: Drive Not Found"
E: Incompatible types.

I think I am off in the “then” statement but I am not sure where I am off.

The THEN and ELSE have to be the same type. Your “THEN” was not cast a a string.

Try:

q: if Exists(name of it as string contains "P") of keys of (keys("Networ") of Keys of key "HKEY_USERS" of registry) then (name of it & ": " & value "RemotePath" of it as string contains "P") of keys of (keys("Network") of Keys of key "HKEY_USERS" of registry as string) else "P: Drive Not Found"
1 Like

There’s…a lot going on here.

Let’s start at the beginning with just Exists(name of it as string contains "P")
The logic there doesn’t do what you think…this block will always return True; because (name of it as string contains "P") is a boolean that will return either True or False, and both True and False ‘exist’.

q: "this is a test"
A: this is a test
T: 0.231 ms
I: singular string

q: (it as string contains "P") of "this is a test"
A: False
T: 0.211 ms
I: singular boolean

q: exists (it as string contains "P") of "this is a test"
A: True
T: 0.161 ms
I: singular boolean

q: exists True
A: True
T: 0.109 ms
I: singular boolean

q: exists False
A: True
T: 0.066 ms
I: singular boolean

Next there’s this other piece, the ‘then’ statement:

then (name of it & ": " & value "RemotePath" of it as string contains "P") 

One way to write this would be

q: (if exists key "P" of it then (name of it & ": " & value "RemotePath" of it as string) of key "P" of it else "Not Found") of keys "Network" of Keys of key "HKEY_USERS" of registry

name of it will get the name of a registry key, which is a string; that’s fine.
However value "RemotePath" of it as string contains "P" is, again, a Boolean, that will either be True or False; and you cannot concatenate a Boolean to the end of a string (unless you cast it ‘as string’, which isn’t what you want anyway).

1 Like

Thanks Jason

This seems to be getting me much closer to my desired result, the only thing is that the results are still returning a line for each mapped drive with the non-P drives calling into the else condition. The sample machine has 3 mapped Drives G, L , P

q: (if exists key “P” of it then (name of it & ": " & value “RemotePath” of it as string) of key “P” of it else “Not Found”) of keys “Network” of Keys of key “HKEY_USERS” of registry
A: Not Found
A: Not Found
A: P: \SERVER\SHARE
T: 1.187 ms

Since we are dealing with strings its looking for some sort of string in the else condition. I can put something like “Not P drive” but it doesnt seem really efficient to return as a property if someone has 14 mapped drives and 13 say “Not P drive”. I would rather see “No P Drive” if it doesnt exist at all and ignore any other drive that is not P.

I tried to deconstruct the if-then-else but the then section breaks into a nonexistent object if the P drive is not the first network drive

q: if (exists key “P” of it of keys “Network” of Keys of key “HKEY_USERS” of registry) then (((name of it & ": " & value “RemotePath” of it as string) of key “P” of it ) of keys “Network” of Keys of key “HKEY_USERS” of registry) else "No P: Drive"
E: Singular expression refers to nonexistent object.

when I use the first network drive (just replacing the letter G) I get a different result, this also is not a server share so it might be invalid results anyways
q: if (exists key “G” of it of keys “Network” of Keys of key “HKEY_USERS” of registry) then (((name of it & ": " & value “RemotePath” of it as string) of key “G” of it ) of keys “Network” of Keys of key “HKEY_USERS” of registry) else "No P: Drive"
A: No P: Drive
T: 0.847 ms

what I would expect is if the P drive exists it would return P: \SERVER\SHARE
If the P drive does not exist it would return “P Drive Not Found” or something like that

q: (if exists key “P” of it then (name of it & ": " & value “RemotePath” of it as string) of key “P” of it else “Not Found”) of keys “Network” of Keys of key “HKEY_USERS” of registry
A: Not Found
A: Not Found
A: P: \SERVER\SHARE
T: 1.187 ms

Actually, since the if statement is all tied around key "P" of it, only that ‘P’ key is being retrieved. The “Not Found” messages are a different case - this is where the HKEY_USERS key has three user keys beneath it, and only one of the three users has a “P” drive mapping. The “Not Found” are for the other two users, not for the other two drive letters.

HKEY_USERS would normally contain hives for each currently logged-on users, as well as for the system accounts like “LocalSystem”.
You could exclude those by filtering out the SIDS, but probably easier instead to search based on user keys of logged on users as the starting registry path. (Note - you’ll need to use “Client Evaluation Mode” in the Fixlet Debugger to see these results)

q: (if exists key "P" of it then (name of it & ": " & value "RemotePath" of it as string) of key "P" of it else "Not Found") of keys "Network" of user keys of logged on users
A: P: \\homenas\Backups
T: 0.064 ms