Expert Software Company : News

miercuri, 12 mai 2010

(VFP) Returning UNC Path associated with a local device

* Windows API
FUNCTION LocalDevice2UNC(tcLocalName)
LOCAL lcUNCBuffer, lnLength, lcLocalName, lcRemoteName
DECLARE INTEGER WNetGetConnection IN WIN32API ;
STRING lpLocalName, STRING @ lpRemoteName, INTEGER @ lplnLength
IF TYPE('tcLocalName') <> "C" OR EMPTY(tcLocalName)
ERROR 11
ENDIF
lcLocalName = ALLTRIM(tcLocalName)
lcUNCBuffer = REPL(CHR(0), 1024)
lnLength = LEN(lcUNCBuffer)
IF WNetGetConnection(lcLocalName, @lcUNCBuffer, @lnLength) = 0
lcRemoteName = LEFT(lcUNCBuffer,AT(CHR(0),lcUNCBuffer)-1)
ELSE
lcRemoteName = ""
ENDIF
RETURN lcRemoteName

*-----------------------------------------------------------------------
* WSH
FUNCTION LocalDevice2UNC(tcLocalName)
LOCAL lcLocalName, lcRemoteName, loFso, loDrive
IF TYPE('tcLocalName') <> "C" OR EMPTY(tcLocalName)
ERROR 11
ENDIF
loFso = CREATEOBJECT("Scripting.FileSystemObject")
lcLocalName = ALLTRIM(tcLocalName)
IF loFso.DriveExists(lcLocalName)
loDrive = loFso.GetDrive(lcLocalName)
lcRemoteName = loDrive.ShareName
ELSE
lcRemoteName = ""
ENDIF
RETURN lcRemoteName

*--------------------------------
* Example
? LocalDevice2UNC("F:")

Niciun comentariu:

Trimiteți un comentariu