LPARAMETER tcPath
LOCAL lcResult, lcRemoteDevice, lcBuffer, lnSize, lnError, lcError
lcResult = ""
lcBuffer = SPACE(200) + CHR(0)
lnSize = LEN(lcBuffer)
IF EMPTY(tcPath) or LEFT(UPPER(tcPath),1) = "C"
RETURN .F. && The C:\ drive is not remote!
ENDIF
*-------------------------------------------------------------------
*-- If the user passed in only one character, this will make sure
*-- the value is correct.
*-------------------------------------------------------------------
lcRemoteDevice = LEFT(tcPath,1) + ":"
*-------------------------------------------------------------------
*-- Add CHR(0) to the end of the string. This will make finding the
*-- end of the return value easier to find.
*-------------------------------------------------------------------
IF RIGHT(lcRemoteDevice, 1) # CHR(0)
lcRemoteDevice = lcRemoteDevice + CHR(0)
ENDIF
*-------------------------------------------------------------------
*-- Open the API function
*-------------------------------------------------------------------
DECLARE INTEGER WNetGetConnection IN Win32API ;
STRING @lcRemoteDevice, STRING @lcBuffer, ;
INTEGER @lnSize
*-------------------------------------------------------------------
*-- Send it in and get the return values
*-------------------------------------------------------------------
lnError = WNetGetConnection(@lcRemoteDevice, @lcBuffer, @lnSize)
IF lnError = 0
lcResult = LEFT(lcBuffer, AT(CHR(0), lcBuffer) - 1)
*-------------------------------------------------------------------
*-- I just want the machine name
*-------------------------------------------------------------------
lcResult = IIF(at("\", lcResult, 3) > 0, ;
left(lcResult,at("\", lcResult, 3)-1), lcResult)
ELSE
lcError = "Unable to obtain the UNC path for drive " + ;
"'"+ UPPER(LEFT(tcPath,2)) + "\'" + " Error = "+ ALLT(STR(lnError))
ENDIF
RETURN lcResult