Results 1 to 15 of 15

Thread: [RESOLVED] Identifying a network drive and finding its path

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2004
    Location
    Canberra, Australia
    Posts
    175

    Resolved [RESOLVED] Identifying a network drive and finding its path

    I'm writing a small tool for ArcMap that invokes one of the tools built into it. For some reason though the tool, and Arc in general, is kind of picky when dealing with network drives. Say I have a network share mapped as the P: drive. The share itself is \\Canberra\Projects. Now, when I send a parameter into the tool that lists the path of a file, I need to send it in as \\Canberra\Projects\file.txt rather than P:\file.txt.

    I can't be sure in advance what the drive mappings might be for a user, so how do I work out if a drive is a network connection rather than a physical drive and how do I extract the network mapping for that drive?

  2. #2
    Banned
    Join Date
    Nov 2005
    Posts
    2,367

    Re: Identifying a network drive and finding its path

    You don't have to worry about it...

    *holds for a sigh of releif*

    I network shared drive is the same as pathing, just not as easy to explain to an end user. Giving it the full name should work regardless of if the mapped drive is P or E or N or I or..... Q

    Cheeky monkey

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jul 2004
    Location
    Canberra, Australia
    Posts
    175

    Re: Identifying a network drive and finding its path

    I think you've missed my point. The Arc tool I'm invoking will not work correctly if I give it the file path in the form P:\file.txt. It complains that it can't find the file basically. I have to put it in the form \\Canberra\Projects\file.txt.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Identifying a network drive and finding its path

    If what you say is true and it will not accept a local path for a network share then you should take a look at this article. I've never had the pleasure myself but I believe that the FileSystemObject and Drive objects should be able to give you the information you're after.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Identifying a network drive and finding its path

    I was hoping that VB 2005 might have something better to offer through the DriveInfo class and/or the My.Computer.FileSystem object but it appears not.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6
    Banned
    Join Date
    Nov 2005
    Posts
    2,367

    Re: Identifying a network drive and finding its path

    God has spoke, bow with me

    Strong server name or pathed, it should work if the network path drive is the same. If it's not that, the divine eye of jmc will explain in detail.

    *keep your head down, he's not done *

    Sarcasm/kidding aside, he knows alot more then I do; i really would like to hear this as well.
    Last edited by sevenhalo; Feb 15th, 2006 at 10:05 PM. Reason: added kidding, seemed less atackggn to me sine i really legitly am asking.

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Identifying a network drive and finding its path

    Quote Originally Posted by sevenhalo
    God has spoke, bow with me

    Strong server name or pathed, it should work if the network path drive is the same. If it's not that, the divine eye of jmc will explain in detail.

    *keep your head down, he's not done *

    Sarcasm aside, he knows alot more then I do; i really would like to hear this as well.
    I have no idea why it wouldn't worked with a local path either. If you just try to perfrom a file system operation the OS should handle any translation required. That's the whole point of mapping a network share to a drive letter in the first place: so that you can treat it like a local path. If it doesn't work in this case then I can only assume that the authors of this component have done something screwy internally. Bad programming on their part I'd say. If you can access the share via the UNC path then there's no point preventing access via the mapped local path. All I'm saying is that if they have somehow prevented use of mapped local paths for shares then the FSO should be able to give you the information you need to get the UNC path from the local path.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jul 2004
    Location
    Canberra, Australia
    Posts
    175

    Re: Identifying a network drive and finding its path

    One of the other Arc products, Arc Catalog, lists drivers/folders in your computers and lets you browse the GIS data therein. It lists physical drives, but not network ones. If you want to access network data you have to tell it the network path for the data. I've absolutely no idea why this is so but it is - it's one of many oddities about the Arc products.

    Anyway, details on the FileSystemObject class seem pretty sketchy - is this really in .NET or just VB? I tried the following code:

    Dim fso As Object
    fso = CreateObject("Scripting.FileSystemObject")
    fso.getDrive("P:")
    Dim temp = fso.Drive.ShareName

    The first three lines work ok, but the last line gives me this error:

    "Public member 'Drive' on type 'IFileSystem3' not found."

    Ok, I'm guessing that the fso has an interface of type IFileSystem3 - but I can find no details on that at all.

  9. #9
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Identifying a network drive and finding its path

    You can look for network drives using WMI Here is a short example, uses the Win32_LogicalDisk WMI class. Looks for a DriveType of "4", which is a network drive.

    ***NOTE - add reference to system.management in order to use
    VB Code:
    1. Dim MyobjectQuery As New System.Management.ObjectQuery("select * from Win32_LogicalDisk")
    2.         Dim MySearcher As New System.Management.ManagementObjectSearcher(MyobjectQuery)
    3.         'loops for all drives on system
    4.         For Each Mgmt As System.Management.ManagementObject In MySearcher.Get()
    5.             'looks for drives with drivetype of 4 which is network drive
    6.             If Mgmt("DriveType").ToString = "4" Then
    7.                 'display caption, which is drive letter
    8.                 MessageBox.Show(Mgmt("Caption").ToString)
    9.                 'below should display network drive path, but couldnt test
    10.                 MessageBox.Show(Mgmt("ProviderName").ToString
    11.             End If
    12.         Next
    For the list of properties for the Win32_LogicalDisk class, check here: http://msdn.microsoft.com/library/de...ogicaldisk.asp

    I couldnt test it on a network drive, as I have none, but a drivetype of "5" worked fine for me.
    Last edited by gigemboy; Feb 15th, 2006 at 10:25 PM.

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Jul 2004
    Location
    Canberra, Australia
    Posts
    175

    Re: Identifying a network drive and finding its path

    Quote Originally Posted by gigemboy
    You can look for network drives using WMI Here is a short example, uses the Win32_LogicalDisk WMI class. Looks for a DriveType of "4", which is a network drive.

    ***NOTE - add reference to system.management in order to use
    VB Code:
    1. Dim MyobjectQuery As New System.Management.ObjectQuery("select * from Win32_LogicalDisk")
    2.         Dim MySearcher As New System.Management.ManagementObjectSearcher(MyobjectQuery)
    3.         'loops for all drives on system
    4.         For Each Mgmt As System.Management.ManagementObject In MySearcher.Get()
    5.             'looks for drives with drivetype of 4 which is network drive
    6.             If Mgmt("DriveType").ToString = "4" Then
    7.                 'display caption, which is drive letter
    8.                 MessageBox.Show(Mgmt("Caption").ToString)
    9.             End If
    10.         Next
    For the list of properties for the Win32_LogicalDisk class, check here: http://msdn.microsoft.com/library/de...ogicaldisk.asp

    I couldnt test it on a network drive, as I have none, but a drivetype of "5" worked fine for me.
    Isn't that VB code rather than .NET code? The ManagementObject class in .NET doesn't seem to have the drivetype property. It also doesn't help me find the network path either. Thanks for trying though.

  11. #11
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Identifying a network drive and finding its path

    lol Of course its VB.NET silly Worked fine on my machine. The managementobject doesnt have that property.. its all part of the WMI OBJECT RETURNED for the WMI Class you specify... try the code out first before you think it doesnt work

    ***EDIT - also look above, I edited my post with the property that should show the network drive path

    P.S. I also don't like being told "thanks for the effort" when it should do exactly what you stated
    Last edited by gigemboy; Feb 15th, 2006 at 10:34 PM.

  12. #12
    Banned
    Join Date
    Nov 2005
    Posts
    2,367

    Re: Identifying a network drive and finding its path

    Gig, stop biting your tongue

    It was a good sugestion, .Net and legacy VB is very close (it almost scares you). Give his suggestion a legit try, don't pass it off. I find myself doing that alot, thinking VB6 people can't help me (not that he is), but they can... MS made it really easy to transition so it's very common to get legacy and .Net development confused.

  13. #13
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Identifying a network drive and finding its path

    Also should be obvious when I mention "add a reference to System.Management"... and I have never been a VB6 programmer

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Jul 2004
    Location
    Canberra, Australia
    Posts
    175

    Re: Identifying a network drive and finding its path

    Quote Originally Posted by gigemboy
    lol Of course its VB.NET silly Worked fine on my machine. The managementobject doesnt have that property.. its all part of the WMI OBJECT RETURNED for the WMI Class you specify... try the code out first before you think it doesnt work

    ***EDIT - also look above, I edited my post with the property that should show the network drive path

    P.S. I also don't like being told "thanks for the effort" when it should do exactly what you stated
    It works fine, thanks. I wasn't sure because the quote tag about your code said "visual basic code" rather than .NET code (and the bit at the bottom says assume all code is .NET unless stated otherwise). I also always use Msgbox rather than MessageBox - on top of it all, I never did much programming in VB6 so I'm not always sure what to look for.

    Thanks for the help.

  15. #15
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: [RESOLVED] Identifying a network drive and finding its path

    hehe no prob. Messagebox.Show is actually more correct to use in .NET. MsgBox is a runtime function carried over from VB6.

    (and the "visual basic code" is put in by the forum software when you use the vbcode tags)
    Last edited by gigemboy; Feb 15th, 2006 at 10:43 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width