1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Function to see if a UNC path is mapped?

Discussion in 'Support' started by Rod Savard, Jul 21, 2010.

  1. Rod Savard

    Joined:
    May 26, 2008
    Messages:
    481
    Likes Received:
    3
    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
     
  2. Jim Cook

    Joined:
    May 20, 2008
    Messages:
    604
    Likes Received:
    0
    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:




    --
    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.
     
  3. Rod Savard

    Joined:
    May 26, 2008
    Messages:
    481
    Likes Received:
    3
    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.
     
  4. Joe Caverly

    Joined:
    Aug 28, 2009
    Messages:
    680
    Likes Received:
    8
    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
     
  5. Joe Caverly

    Joined:
    Aug 28, 2009
    Messages:
    680
    Likes Received:
    8
    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
     
  6. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,952
    Likes Received:
    30
    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:
     
  7. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,952
    Likes Received:
    30
    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:
     
  8. Joe Caverly

    Joined:
    Aug 28, 2009
    Messages:
    680
    Likes Received:
    8
    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
     
  9. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,190
    Likes Received:
    11
    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:


     
  10. Rod Savard

    Joined:
    May 26, 2008
    Messages:
    481
    Likes Received:
    3
    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!
     

Share This Page