Get UNC Path for Mapped Drive
Author: kevin_darbin@hargreaveslansdown.co.uk (kevindarbin)
Hello,
Does anyone know how to get the UNC path for a file that is selected via a mapped network drive?
We allow our users to "link" documents into our application by selecting them via the "filebox" statement. If they select a file from a network drive, then the path returned is that of the network drive. As not all users have their network drives mapped exactly the same, we would rather return / get the UNC path for the file. Is this possible?
Thanks,
Kevin
Hi Kevin
It's possible to make a call out to the windows function WNetGetConnectionW in the DLL c:\\windows\\system32\\mpr.dll.
First add c:\\windows\\system32\\mpr.dll to the USER_3GL section of your asn file then create your signature for the WNetGetConnectionW function
- Create a signature called MPR (this name can be anything)
- Set the implementation to be of type C and under the properties for this implementation set the "Character set used" to be UTF-16
- Create a new operation WNETGETCONNECTIONW and set it's literal name to be WNetGetConnectionW (leave the return as into $status and type long)
- Create an IN parameter called LOCALNAME of type string, an interface of char * with a length of 4
- Create an INOUT parameter called REMOTENAME of type string, an interface of char * with a length of 1024
- Create an INOUT parameter called LENGTH of type numeric and interface of long
Compile the signature
To call the function use code similar to
variables
string vLocal
string vUNC
numeric vLen
endVariables
vLocal = "z:"
vLen = 254
activate "MPR".WNetGetConnectionW(vLocal, vUNC, vLen)
message/info vUNC
Hope this helps,
Mike
Author: Mike Taylor (michael.taylor@uniface.com)
Get UNC Path for Mapped Drive
Author: kevin_darbin@hargreaveslansdown.co.uk (kevindarbin)
Hello,
Does anyone know how to get the UNC path for a file that is selected via a mapped network drive?
We allow our users to "link" documents into our application by selecting them via the "filebox" statement. If they select a file from a network drive, then the path returned is that of the network drive. As not all users have their network drives mapped exactly the same, we would rather return / get the UNC path for the file. Is this possible?
Thanks,
Kevin
Hi Mike,
I just tried your solution, and it works like a dream !
Thanks very much for your help.
Regards,
Kevin
Author: kevindarbin (kevin_darbin@hargreaveslansdown.co.uk)