Function to see if a UNC path is mapped?

May 26, 2008
537
4
Is there a built in function that will determine if a UNC path is mapped, and return the drive letter if so?

Sort of the opposite of how @TRUENAME will return the UNC path of a mapped drive letter.

Thanks
 
May 20, 2008
603
0
Sammamish, WA
Something like this might get you started.

echo %@word[1,%@execstr[net use | ffind /k/m/t"\\computer\share"]]

On Wed, Jul 21, 2010 at 2:57 PM, Rod Savard <> wrote:


> Is there a built in function that will determine if a UNC path is mapped,
> and return the drive letter if so?
>
> Sort of the opposite of how @TRUENAME will return the UNC path of a mapped
> drive letter.
>
> Thanks
>
>
>
>
>



--
Jim Cook
2010 Sundays: 4/4, 6/6, 8/8, 10/10, 12/12 and 5/9, 9/5, 7/11, 11/7.
Next year they're Monday.
 
May 26, 2008
537
4
Thanks, but I was hoping there might be a purely internal function that does not require running an external command. I already know how to do it that way :) thanks though.
 
Thanks, but I was hoping there might be a purely internal function that does not require running an external command. I already know how to do it that way :) thanks though.

Hi,
Take a look at http://www.jpsoft.com/forums/showthread.php?t=1344

While it does not return the drive letter, I'm sure that it is possible to extend this .BTM to do so using the @WMI Variable Function.

I'll see if this is possible (it should be).

Joe
 
Here's what I've found.

I have drive I: and drive G: mapped on my system. Using WMI I found the following;

Code:
wmiquery /a root\CIMV2 "SELECT * FROM Win32_MappedLogicalDisk WHERE Name = 'G:'"
Caption = G:
Compressed = False
DeviceID = G:
FileSystem = FAT32
FreeSpace = 216183439360
MaximumComponentLength = 255
Name = G:
ProviderName = \\Storage-11c5\PUBLIC\JCaverly_Backup
SessionID = 66992
Size = 499983122432
SupportsDiskQuotas = False
SupportsFileBasedCompression = False
SystemCreationClassName = Win32_ComputerSystem
SystemName = LRDELLXP
VolumeName = PUBLIC
Code:
echo %@wmi[root\CIMV2 "SELECT * FROM Win32_MappedLogicalDisk WHERE Name = 'G:'"]
G:
False
G:
FAT32
216183439360
255
G:
\\Storage-11c5\PUBLIC\JCaverly_Backup
66992
499983122432
False
False
Win32_ComputerSystem
LRDELLXP
PUBLIC
Code:
echo %@wmi[root\CIMV2 "SELECT * FROM Win32_MappedLogicalDisk WHERE Name = 'I:'"]
I:
False
I:
FAT32
216183439360
255
I:
\\Storage-11c5\PUBLIC\JLC\My Documents\My Music\My MP3s
66992
499983122432
False
False
Win32_ComputerSystem
LRDELLXP
PUBLIC
Code:
wmiquery /a root\CIMV2 "SELECT * FROM Win32_MappedLogicalDisk WHERE ProviderName = '\\\\Storage-11c5\\PUBLIC\\JCaverly_Backup'"
Caption = G:
Compressed = False
DeviceID = G:
FileSystem = FAT32
FreeSpace = 216183439360
MaximumComponentLength = 255
Name = G:
ProviderName = \\Storage-11c5\PUBLIC\JCaverly_Backup
SessionID = 66992
Size = 499983122432
SupportsDiskQuotas = False
SupportsFileBasedCompression = False
SystemCreationClassName = Win32_ComputerSystem
SystemName = LRDELLXP
VolumeName = PUBLIC
Code:
wmiquery /a root\CIMV2 "SELECT * FROM Win32_MappedLogicalDisk WHERE ProviderName = '\\\\Storage-11c5\\PUBLIC\\JLC\\My Documents\\My Music\\My MP3s'"
Caption = I:
Compressed = False
DeviceID = I:
FileSystem = FAT32
FreeSpace = 216183439360
MaximumComponentLength = 255
Name = I:
ProviderName = \\Storage-11c5\PUBLIC\JLC\My Documents\My Music\My MP3s
SessionID = 66992
Size = 499983122432
SupportsDiskQuotas = False
SupportsFileBasedCompression = False
SystemCreationClassName = Win32_ComputerSystem
SystemName = LRDELLXP
VolumeName = PUBLIC
You can use @EXECSTR to return whatever line that you want from the command.

Hope this helps.

Joe
 
May 20, 2008
11,401
99
Syracuse, NY, USA
On Wed, 21 Jul 2010 21:23:56 -0400, Joe Caverly
<> wrote:

|I have drive I: and drive G: mapped on my system. Using WMI I found the following;

Nice one, Joe.

You can make the output terser and do a backwards lookup (which is
what the OP wants to do). Note the (apparently necessary) doubling of
backslashes.

Code:
wmiquery /a root\CIMV2 "SELECT ProviderName FROM
Win32_MappedLogicalDisk WHERE Name = 'K:'"
\\lucky\e$

wmiquery /a root\CIMV2 "SELECT Name FROM Win32_MappedLogicalDisk WHERE
ProviderName = '\\\\lucky\\e$'"
K:

This suggests:

Code:
FUNCTION ISPATHMAPPED `%@execstr[wmiquery /a root\CIMV2 "SELECT
Name FROM Win32_MappedLogicalDisk WHERE ProviderName = '%1'"]`

echo %@ispathmapped[\\\\lucky\\e$]

K:
 
May 20, 2008
11,401
99
Syracuse, NY, USA
Even better,

Code:
v:\> FUNCTION ISPATHMAPPED `%@execstr[wmiquery /a root\CIMV2
"SELECT Name FROM Win32_MappedLogicalDisk WHERE ProviderName '%@replace[\,\\,%1]'"]`

v:\> echo %@ispathmapped[\\lucky\e$]
K:
 
Note the (apparently necessary) doubling of
backslashes.
This is because ProviderName is not a key.

If it were a key, then the backslashes would not have to be doubled.

At least, that is what I have discovered through trial and error.

In http://www.jpsoft.com/forums/showthread.php?t=1344 I used %@replace[\,\\,%_cwd] to allow for entry of a normal path with backslashes, which transforms a normal path into the required path for the query.

Joe
 

samintz

Scott Mintz
May 20, 2008
1,503
16
Solon, OH, USA
You can use the @WMI function instead of @EXECSTR[ wmiquery /a ...]

FUNCTION ISPATHMAPPED `%@wmi[root\CIMV2 "SELECT Name FROM
Win32_MappedLogicalDisk WHERE ProviderName = '%@replace[\,\\,%1]'"]`

echo %@ispathmapped[\\lucky\e$]

K:

-Scott

vefatica <> wrote on 07/21/2010 09:47:46 PM:


> On Wed, 21 Jul 2010 21:23:56 -0400, Joe Caverly
> <> wrote:
>
> |I have drive I: and drive G: mapped on my system. Using WMI I found
> the following;
>
> Nice one, Joe.
>
> You can make the output terser and do a backwards lookup (which is
> what the OP wants to do). Note the (apparently necessary) doubling of
> backslashes.
>
>
> Code:
> ---------
> wmiquery /a root\CIMV2 "SELECT ProviderName FROM
> Win32_MappedLogicalDisk WHERE Name = 'K:'"
> \\lucky\e$
>
> wmiquery /a root\CIMV2 "SELECT Name FROM Win32_MappedLogicalDisk WHERE
> ProviderName = '\\\\lucky\\e$'"
> K:
> ---------
> This suggests:
>
>
> Code:
> ---------
> FUNCTION ISPATHMAPPED `%@execstr[wmiquery /a root\CIMV2 "SELECT
> Name FROM Win32_MappedLogicalDisk WHERE ProviderName = '%1'"]`
>
> echo %@ispathmapped[\\\\lucky\\e$]
>
> K:
> ---------
>
>
>
 
May 26, 2008
537
4
Excellent! Didn't even think of using WMI.

Also I changed it from "%@execstr wmiquery" to just "%@wmi". Works great!

Code:
function IsPathMapped `%@wmi[root\cimv2, "SELECT Name from Win32_MappedLogicalDisk WHERE ProviderName = '%@replace[\,\\,%1]'"]`
Thanks guys!
 
Similar threads
Thread starter Title Forum Replies Date
vefatica Documentation Function parameters Support 0
Jay Sage Documentation Function @DRIVE Missing in Help Lists Support 0
Joe Caverly How to? Get name of current LIBRARY function? Support 4
x13 WeekNum function? Support 3
Joe Caverly No blank line in TEXT...ENDTEXT in a LIBRARY function Support 8
cgunhouse Ctrl-C from within a library function Support 6
C email[string] function Support 10
R FUNCTION to count NUMBER of files matching a pattern and specific length/not length Support 4
Dick Johnson Using the @instr function Support 5
vefatica '}' in a library function? Support 3
D Can the argument to RETURN be a function expansion? Support 3
J Trouble with @full[] function. Support 3
Fross Quick Function Question Support 17
vefatica Quoting @Function parameters? Support 0
Joe Caverly Debugging a LIBRARY function Support 10
Steve Pitts Documentation @CAPI function summary Support 0
x13 %x$ in function Support 3
thorntonpg @eval function, interesting results any explanation? Support 3
x13 Function to get interface user-defined name? Support 10
vefatica Fixed Help @FUNCTION, missing paragraph Support 8
Mordachai Variable followed by function constantly failing... Support 5
nickles Call a complex function Support 13
M Fixed Cannot use the "Browse..." function in "Find files/text" dialogbox Support 2
R Function #IDOW returns only 2 characters Support 10
T scrput `` in alias or function Support 2
S International characters - TYPE vs %@LINE function Support 5
JohnQSmith WAD @REPEAT function Support 15
vefatica WAD Nested variable expansion in PDIR's @function[*]? Support 13
R In addition to ALIAS /Z and FUNCTION /Z, HISTORY /Z? Support 1
A pdir function usage Support 3
nikbackm FUNCTION with variable number of arguments Support 17
S %@REGQUERY function Support 1
Dan Glynhampton Documentation v15 help: Error on @TRIMALL function page Support 0
M Why doesn't this @Field function work? Support 0
fpefpe How to? user function Support 1
M Why is this function getting these results in these circumstances? Support 6
A WAD function return values with parentheses prevent evaluation of additional functions Support 31
M Just an out-of-curiosity question the List command vs. the @Lines function... Support 13
M How to? Just verification for what I think I know regarding "Function"... Support 4
Frank How to? need help with "function" Support 10
Joe Caverly How to? Function Key With INPUT Support 5
M How to? "Function" and "%[xxx]" Support 7
M Kind of a out-of-curiosity question re. the "Function" command... Support 5
M Simple question about "Function" command... Support 4
M Just a curiosity question related to the "Function" command... Support 2
C not sure of windows registry function use Support 2
Phileosophos The @urlencode function doesn't seem to URL encode Support 16
J issue to have "if" inside function Support 3
Frank is the search-function in VIEW working? Support 2
M Weird @Index function result... Support 7

Similar threads