Solved

Getting the full UNC path.

Posted on 1997-08-06
12
1,244 Views
Last Modified: 2013-12-03
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.
0
Comment
Question by:md041797
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
  • +1
12 Comments
 
LVL 4

Expert Comment

by:davmarc
ID: 1403278
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
 
LVL 4

Author Comment

by:md041797
ID: 1403279
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
 
LVL 3

Accepted Solution

by:
byang earned 100 total points
ID: 1403280
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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 4

Author Comment

by:md041797
ID: 1403281
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
 
LVL 5

Expert Comment

by:y96andha
ID: 1403282
How do you know that the drive is shared?
0
 
LVL 4

Author Comment

by:md041797
ID: 1403283
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
 
LVL 5

Expert Comment

by:y96andha
ID: 1403284
WNetEnumResource or NetShareEnum can both be used.
0
 
LVL 3

Expert Comment

by:byang
ID: 1403285
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
 
LVL 4

Author Comment

by:md041797
ID: 1403286
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
 
LVL 5

Expert Comment

by:y96andha
ID: 1403287
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
 
LVL 4

Author Comment

by:md041797
ID: 1403288
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
 
LVL 5

Expert Comment

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

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Duplicates in Aggregate Query 3 53
Application vs Workbook.applicaiton 3 49
Visual Studio 2015 locks debug executable 9 268
How can my static class become undefined?? 8 94
This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question