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

x
?
Solved

Server path to Mapped Network Drive

Posted on 2004-08-24
4
Medium Priority
?
370 Views
Last Modified: 2013-11-20
Hi,

My OS is WinXP SP1. The following path is mapped to drive Z:

\\med2\transfer where med2 is the server name and transfer is the share folder on the server.

In my MFC dialog program, I get this path

\\med2\transfer\data\log.txt

So my question is how to convert the above path to this Z:\data\log.txt programmatically.

I have tried Volume Mount Point functions, but can't find the solution.

Thanks for your help

-David
0
Comment
Question by:htang_us
[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
  • 2
4 Comments
 

Expert Comment

by:nickblah42
ID: 11884308
Use NetShareEnum to enumerate the current network shares.  SHARE_INFO_2 (for NT, share_info_50 for 9x) has the path for the share with the name.

Parse the UNC path for the \\[server]\[share] part, enum shares on server, compare share name with enum results (case insensitive), find matching share, read out local path, construct final local path.

- Nick
0
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 200 total points
ID: 11886330
#include <process.h>
#include <string>
#include <fstream>

using namespace std;

char getDriveFromUNC(const string uncPath)
{    
     system("net use >%TEMP%\\mapall.lis");
     int pos = uncPath.find('\\', 2);
     if (pos == string::npos)
          return '\0';
     string server = uncPath.substr(0, pos);
     int pos1 =  uncPath.find('\\', pos+1);
     if (pos1 == string::npos)
          return '\0';
     string share = uncPath.substr(pos, pos1-pos);
   

     char   temp[256];
     int     lent = GetEnvironmentVariable("TEMP", temp, sizeof(temp));
     string tempfile = temp;
     tempfile += "\\mapall.lis";
     ifstream ifs(tempfile.c_str());
     string contents, line;
     while (!ifs.fail() && !ifs.eof())
     {
          getline(ifs, line);
          pos = line.find(server);
          if (pos != string::npos)
          {
              pos1 = line.find(share, pos + server.length());
              if (pos1 != string::npos)
              {
                     pos1 = line.find(':');
                     if (pos1 != string::npos && pos1 < pos)
                         return line[pos1-1];
              }
          }
      }
      return '\0';
}
     
Note, that solution is case-sensitive. You should turn all strings to upper-case if uncPath might have wrong case.

Regards, Alex

     

     
0
 
LVL 2

Author Comment

by:htang_us
ID: 11895056
Hi, Nick,

I tried your solution and NetShareEnum always return ERROR_ACCESS_DENIED, so this solution requires user has priviledge to access the remote host, not only the share folder.

Alex,

Thanks for your code snippet that solves my question.

Thanks again, Nick and Alex

-David
0
 

Expert Comment

by:nickblah42
ID: 11895126
Oh... my bad.  You want NetUseEnum for the local devices.  This does the same thing as the 'net use' shell command.

Glad you got it working. :)

- Nick
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

705 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