Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Find a UNC path to a file on local drive

2,494 views
Skip to first unread message

P Chase

unread,
Jan 21, 2008, 6:22:32 AM1/21/08
to
Hi,

I have a requirement to find a UNC path, or a FILE: URL, to a file on
the local machine. The idea is that a remote computer that can see my
shares will be able to use this to access the file on my machine.

For instance, say I have shared my C: drive on my machine WIBBLE with
share name PETE_C, I would like the function, given "c:\users\peterc
\myfile.txt" to return something like "\\WIBBLE\PETE_C\users\peterc
\myfile.txt". A machine on the LAN that could see my machine and had
permission to access my shares could use that path to access the file.

Hopefully, you understand that shares can have a different name to the
drive or directory that is being shared. So that means that you cannot
do a simple-minded translation - you must find out what shares are
available on the machine.

I hoped that WNetGetUniversalName() did what I want, but it doesn't.
It only works if the file is on a drive that is connected to a
*remote* machine. I need an equivalent for where the file is local.

Any pointers would be appreciated.

Christian ASTOR

unread,
Jan 21, 2008, 12:49:33 PM1/21/08
to
On 21 jan, 12:22, P Chase <peter.ch...@globalgraphics.com> wrote:
> Hi,
>
> I have a requirement to find a UNC path, or a FILE: URL, to a file on
> the local machine. The idea is that a remote computer that can see my
> shares will be able to use this to access the file on my machine.
>
> For instance, say I have shared my C: drive on my machine WIBBLE with
> share name PETE_C, I would like the function, given "c:\users\peterc
> \myfile.txt" to return something like "\\WIBBLE\PETE_C\users\peterc
> \myfile.txt". A machine on the LAN that could see my machine and had
> permission to access my shares could use that path to access the file.

The share name is normally \\WIBBLE\c$\users\peterc\myfile.txt
(GetComputerName() for WIBBLE)
You don't have to enumerate the shares with WNetEnumResource() and
call
NetShareGetInfo() to get the local name for each share

0 new messages