Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Getting UNC string from mapped drive
Message
De
07/11/2001 14:48:27
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00578658
Message ID:
00578694
Vues:
16
>I have a need to find the the UNC equivalent to mapped drives. For instance some of my users are mapped to f:\download others have the mapping of r:\download. I need to find some way of getting the unc equivalent.
>
>example.
>
>j= getfile() && this will return the file I want to put in the database.
>
>I would need to get the unc equivalent with and maybe interrogate what unc equivalent of J would be.
>
>Thank you in advance.
>
>Joe Hendren

Joe,

The WSH is great stuff, but I don't rely on it for mass distribution because not all machines have it loaded.

Try this:


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

Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform