Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieve computer share name from a drive letter? 1

Status
Not open for further replies.

Webrookie

Programmer
May 18, 2000
112
US
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?
 
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(&quot;WScript.Network&quot;)
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. :)
 
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.

:)
 
Awesome Jon...You are a genius! Thank you very much
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top