Getting the full UNC path.

Given a filename C:\dir\file.dot, how can you get the UNC pathname \\MyComputer\C\dir\file.dot?  This needs to work on Win95 and NT4.  The file may be on a mapped drive or it may be local.
LVL 4
md041797Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

davmarcCommented:
WNetGetUniversalName() does exactly what you want.
See also KB article Q131416 for some important notes about using it under Windows 95.

By the way, ScLocalPathFromUNC() seems to accomplish the same need. Take in account that it is part of MAPI (header mapiutil.h).

Davide Marcato.


0
md041797Author Commented:
This does not work on Win95.  I have already attempted the kb method, but it will not enum a local resource.  This is part of my stated requirements.

The problem is this:  I have a server process which may be running on any machine on the net.  The client process loads, then using the argv of the startup, it creates a read and a write mailslot using the UNC name of the dir where the exe is located.  It then attempts to connect to the server via the mailslot.  If a server is not found, it loads the server process on the local machine.  The server then checks its own argv to create its mailslots and the conversation ensues from there.

I am using the UNC name of the startup dir, because there may be multiple copies of the product on the network, and they each keep their own data files, so in order to prevent collision, they use different names for the slots.  

You can see that the server may be running on any machine, so I need a way to get the UNC of the directory using the same share/server name whether the resource is local or remote.

The function ScUNCFromLocalPath will not be supported in future versions of MAPI.  It's not supported in NT4 either.
0
byangCommented:
When there's no simple API call, there's always the hard way
:
use GetDriveType() to determine if the drive letter is a local hard drive. If it is, call GetComputerName() and then construct the UNC path yourself.
If it's not, use WNet* functions to find remote name, then construct the UNC path yourself.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

md041797Author Commented:
OK, I missed this one.  The other piece missing is what is the share name for the local drive (viewed across the network).  Without that I'm still in a hole.
0
y96andhaCommented:
How do you know that the drive is shared?
0
md041797Author Commented:
I don't, but if its not I could just use the drive letter as the share name by default.  If its not shared, it means that the client and the server are both running on the same machine, so any old name would work by default.

Anyhow, I found a better solution.  It was a head smacker.

All I need to do is have the server generate a mailslot name via random number generator, and then publish the name in a file within the same directory as the data file.  Clients could then read the file, get the slot name and then create the slot and go to work.  smack.

It just goes to show:  If you have a hard problem, drop it and work on something else.  When you wake up tomorrow morning, the answer will be on the tip of your brain.

I am still wondering how to get share names, so if byang can give me an answer, I will give an A.  Else I will give a C later.
0
y96andhaCommented:
WNetEnumResource or NetShareEnum can both be used.
0
byangCommented:
You just use the WNet* functions to enumerate all network resources you're currently connected to, and get info about them. Just look it up, that's what I do because who can memorize all the details about 1000 windows API calls ?
0
md041797Author Commented:
The NetShareEnum is obsolete.  The WNetEnumResource only tells you what resources are available to your process.

For example, the server process loads on the local machine.  It then needs to know what the share name of the disk is so it can know what slot name to create.  If the server creates a slot called \\mailslot\c\ProductDir and a client creates a slot called  \\mailslot\TheServer\ShareName\ProductDir, they will obviously not connect.

So the question remains, how do you find the share names of your "local" disks?



0
y96andhaCommented:
NetShareEnum can be used anyway, and is the simplest way to get the information. Do you mean that WNetEnumResource wouldn't work because your process might not have the access rights required to connect to the share?
0
md041797Author Commented:
No, what I mean is how can the server process figure out where its exe is located on the network so that it knows what mailslot name to create?

If the exe is located on the same machine that's  running the server process, does it have any way of knowing what the share name of its files are viewed from across the network?

WNetEnum does not give you the share names of shared drives if they are on the local machine.


0
y96andhaCommented:
OK, I'm sorry, I've never used WNetEnum, only NetShareEnum, and that returns all shares where I've used it (NT Workstation).
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.