Solved

Getting the full UNC path.

Posted on 1997-08-06
12
1,234 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
  • 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
 
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

757 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now