Solved

Server path to Mapped Network Drive

Posted on 2004-08-24
4
352 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 50 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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 …
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.
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…

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