Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Getting the full UNC path.

Posted on 1997-08-06
12
Medium Priority
?
1,247 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 200 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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
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…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

715 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