Link to home
Start Free TrialLog in
Avatar of md041797
md041797

asked on

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.
Avatar of davmarc
davmarc

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.


Avatar of md041797

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of byang
byang
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
How do you know that the drive is shared?
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.
WNetEnumResource or NetShareEnum can both be used.
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 ?
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?



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?
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.


OK, I'm sorry, I've never used WNetEnum, only NetShareEnum, and that returns all shares where I've used it (NT Workstation).