×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Retrieve computer share name from a drive letter?

Retrieve computer share name from a drive letter?

Retrieve computer share name from a drive letter?

(OP)
say I have "h:\" mapped to "\\computername\bobsdrive"

What is the proper code to go about retrieving the name?
I want to retrieve "\\computername\bobsdrive"

Do I have to go about using API?

Could someone help me out with this one?

RE: Retrieve computer share name from a drive letter?

I'd use the Windows Scripting Host.
Something like this:

FUNCTION GetUNCPath
  LPARAMETERS tcMappedDriveLetter

  LOCAL lcRetPath,WshNetwork,oDrives,i

  lcRetPath = '
  IF TYPE('tcMappedDriveLetter')<>'C'
    RETURN lcRetPath
  ENDIF
  tcMappedDriveLetter=LEFT(tcMappedDriveLetter,1)
  IF !DIRECTORY(tcMappedDriveLetter+':')
    RETURN lcRetPath
  ENDIF

  WshNetwork = CREATEOBJECT("WScript.Network")
  oDrives = WshNetwork.EnumNetworkDrives

  *NOTE: this array is 0 based
  FOR i = 0 To oDrives.Count - 1
    IF oDrives.Item(i)=tcMappedDriveLetter
      lcRetPath=oDrives.Item(i+1)
      EXIT
    ENDIF
  ENDFOR

  RETURN lcRetPath
ENDFUNC

If you can't use the WSH for whatever reasons, you can still do it with the API. I just prefer the WSH. :-)

Jon Hawkins
jonscott8@yahoo.com

Carpe Diem! - Seize the Day!

RE: Retrieve computer share name from a drive letter?

(OP)
Thank you Jon for your reply...I'm sure we can use WSH, but who knows.  We're gonna try it now.....

I'll let you know.

:)

RE: Retrieve computer share name from a drive letter?

(OP)
Awesome Jon...You are a genius!  Thank you very much

RE: Retrieve computer share name from a drive letter?

Awesome Jon...You are a genius!

LOL. Thanks. I'd been down the mapped drive path before, so it was fairly easy for me to recollect.

Thank you very much

You're welcome. Glad I could help.

Jon Hawkins
jonscott8@yahoo.com

Carpe Diem! - Seize the Day!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close