This might be of use ...
Note: The variable "rcUncFileName" is the mapped drive path .. goes into
the GetUncPath function and is returned by reference as the UNC path for
that mapped name - hence the name seems odd.
DECLARE INTEGER WNetGetConnection IN WIN32API ;
STRING @lpLocalPath, ;
STRING @lpBuffer, ;
INTEGER @lpBufferSize
*- Returns -1 if fails.
lnStatus = getuncpath(@rcUncFileName)
GetUNCPath ...
LPARAMETERS rcmappedpath, vnbuffersize
* set up some variables so the appropriate call can be made
LOCAL lclocalpath, lcbuffer, lnbuffersize, lnresult, lcstructurestring,
lcreturnvalue
LOCAL lcdrive, lcpath, lcMachinename
STORE -1 TO lnResult
STORE "" TO lclocalpath, lcbuffer, lnbuffersize, lnresult,
lcstructurestring, lcreturnvalue, lcdrive, lcpath
IF VARTYPE(m.rcmappedpath) = "C"
* split up the passed path to get just the drive
* just take the first two characters - we'll put it all back
together later. If the first two characters
* are not a valid drive, that's OK. The error value returned from
the function call will handle it.
* case statement ensures we don't get the "cannot access beyond end
of string" error
DO CASE
CASE LEN(m.rcmappedpath) > 2
lcdrive = LEFT(m.rcmappedpath, 2)
lcpath = SUBSTR(m.rcmappedpath, 3)
CASE LEN(m.rcmappedpath) <= 2
lcdrive = m.rcmappedpath
lcpath = ""
ENDCASE
* set to +1 to allow for the null terminator
lnbuffersize = IIF(VARTYPE(m.vnBufferSize) = "N", m.vnbuffersize,
500) + 1
lclocalpath = m.lcdrive
lcbuffer = SPACE(m.lnbuffersize)
* now call the dll
lnresult = WNetGetConnection(@lclocalpath, @lcbuffer, @lnbuffersize)
*---------------------------------------------------------------------------
-------------------------------------------
*- WNetGetConnection return codes
*---------------------------------------------------------------------------
-------------------------------------------
*- -1 Mapped path (parameter) is not character
*- 0 Success
*- 50 The dwInfoLevel parameter was set to 0x00000001
(UNIVERSAL_NAME_INFO_LEVEL)
*- but the network provider does not support UNC names.
This function is not supported by any of the network providers.
*- 234 The buffer pointed to by lpBuffer is too small.
*- The function sets the variable pointed to by lpBufferSize to
the required buffer size.
*- 1200 The string pointed to by lpLocalPath is invalid.
*- 1201 There is no current connection to the remote device, but
there is a remembered (persistent) connection to it.
*- 1203 None of the providers recognized this local name as having a
connection.
*- However, the network is not available for at least
one provider to whom the connection may belong.
*- 1208 A network-specific error occurred. Use the WNetGetLastError
function to obtain a description of the error.
*- 1222 There is no network present.
*- 2250 The device specified by lpLocalPath is not redirected.
*---------------------------------------------------------------------------
-------------------------------------------
DO CASE
CASE INLIST(m.lnresult, 0, 1201)
*- string translated successfully
lcstructurestring = ALLTRIM(m.lcbuffer)
rcmappedpath = LOWER(LEFT(m.lcstructurestring, AT(CHR(0),
m.lcstructurestring) - 1) + m.lcpath)
*- Local drives to not translate correctly to UNC with this
function. The code below corrects the string to have the
*- machineid included as part of the UNC path.
IF ATC(":", m.rcmappedpath) = 2
lcMachinename = LOWER(GETWORDNUM(SYS(0), 1, "#"))
rcmappedpath = "\\" + RTRIM(m.lcMachinename) + "\" +
LEFT(m.rcmappedpath, 1) + "$" + SUBSTR(m.rcmappedpath, 3)
ENDIF
CASE m.lnresult = 234
*- The buffer pointed to by lcbuffer is too small.
lnresult = getuncpath(@rcmappedpath, m.lnbuffersize + 100)
CASE m.lnresult = 2250
*- Is this a local drive ?
IF ATC(":", m.rcmappedpath) = 2 AND spDIRECTORY(LEFT(m.rcmappedpath,
2), 1)
lcMachinename = LOWER(GETWORDNUM(SYS(0), 1, "#"))
rcmappedpath = "\\" + RTRIM(m.lcMachinename) + "\" +
LEFT(m.rcmappedpath, 1) + "$" + SUBSTR(m.rcmappedpath, 3)
*- Set this to be a valid drive so return value indicates this is a
drive with UNC mapping.
lnresult = 0
ENDIF
ENDCASE
ENDIF
RETURN m.lnResult
-----Original Message-----
From: ProfoxTech [mailto:[email protected]] On Behalf Of Ted
Roche
Sent: Tuesday, 11 April 2017 8:11 AM
To: [email protected]
Subject: Re: Easy way to get UNC from drive mapping?
For a hack, you can shell out to a command window, issue NET USE and capture
the output, and parse that.
On Mon, Apr 10, 2017 at 5:15 PM, Mike <[email protected]> wrote:
> FWIW, the REGISTRY solution you sent a link to doesn't work well for me.
>
> I have 2 mapped drives to a local server (same subnet as my
> workstation) and
> 4 mapped drives to remote servers via VPN.
>
> The REGISTRY key you send the link to only has one of the 6 mappings.
>
> I suspect there's other sources, but sorry, I don't know what they are.
>
> Mike Copeland
>
>
> [email protected] wrote:
>>
>> I use GETFILE() to select a file from the network. I want the
>> resulting filename (saved elsewhere) to have the UNC drive mapping
>> instead of the mapped drive letter. Just wanted to check to see if
>> anyone has this before I stick-build it using registry classes. (See
>> https://pattersonsupport.custhelp.com/app/answers/detail/a_id/8981/~/
>> viewing-the-unc-path-for-a-mapped-drive)
>>
>> Thanks!
>> --Mike
>
>
[excessive quoting removed by server]
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message:
http://leafe.com/archives/byMID/profox/[email protected]
** All postings, unless explicitly stated otherwise, are the opinions of the
author, and do not constitute legal or medical advice. This statement is added
to the messages for those lawyers who are too stupid to see the obvious.