Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Get a real path from a network shared

Posted on 2002-04-26
9
Medium Priority
?
366 Views
Last Modified: 2010-04-02
Hi !

I need a source code for get the real path from a network shared name... like:

GetRealPath( "\\\\computer\\shared" )
-> return "c:\windows\test"

Thanks
0
Comment
Question by:masvmasv
[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
  • 3
9 Comments
 
LVL 32

Expert Comment

by:jhance
ID: 6971796
There is no way since a "real" path to a UNC may not exist.
0
 
LVL 86

Expert Comment

by:jkr
ID: 6972053
0
 
LVL 86

Expert Comment

by:jkr
ID: 6972064
0
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.

 
LVL 86

Expert Comment

by:jkr
ID: 6972067
0
 
LVL 86

Expert Comment

by:jkr
ID: 6972071
Tend to object, jhance :o)

'NetShareGetInfo()' will provide the local name of a share - I wrote that one a while ago:

(EE's choking on that, so I'll have to split the post)
0
 
LVL 86

Accepted Solution

by:
jkr earned 400 total points
ID: 6972073
/*
 *  shrlocal.cpp  -   retrieves the server-local name of a network share
 
 *
 *  Compile:    cl shrlocal.cpp
 *
 *  That's it ;-)
 */

#define UNICODE
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include <lmcons.h>
#include <lmerr.h>
#include <lmshare.h>
#include <lmaccess.h>
#include <lmapibuf.h>

#pragma     comment     (     lib,     "netapi32.lib")

#ifdef __cplusplus
extern "C"
{
#endif

int     __cdecl               wmain                         (     int                    argc,    
                                                            wchar_t**          argv
                                                       );

#ifdef __cplusplus
}
#endif

NET_API_STATUS     GetShareLocalName     (     wchar_t*     pwszShareName,
                                                  wchar_t*     pwszLocalName,
                                                  DWORD          dwSize
                                             )
{
     SHARE_INFO_2*     psi2     =     NULL;
     NET_API_STATUS     nas          =     0;

     wchar_t               awcServer     [     LM20_CNLEN]     =     L"";
     wchar_t               awcShare     [     LM20_NNLEN];

     wchar_t*          pwc;
     wchar_t*          pwcBuf;

     if     (     pwc     =     wcsstr     (     pwszShareName,     L"\\\\"))
          {
               pwcBuf     =     new     wchar_t     [     wcslen     (     pwszShareName)];

               wcscpy     (     pwcBuf,     pwszShareName);

               if     (     !(     pwc     =     wcsstr     (     pwcBuf     +     2,     L"\\")))
                    {
                         delete     []     pwcBuf;
                         
                         return     (     NERR_BadComponent);
                    }
                else     *pwc     =     L'\0',     pwc++;

               wcscpy     (     awcServer,     pwcBuf);
               wcscpy     (     awcShare,     pwc);

               delete     (     pwcBuf);

#ifdef     _DEBUG
                wprintf     (     L"\nServer %s Share %s\n",     awcServer,     awcShare);
#endif

          }
      else
          {
               wcscpy     (     awcShare,     pwszShareName);
          }


     if     (     NERR_Success     ==     (     nas     =     NetShareGetInfo (     awcServer,
                                                                                awcShare,
                                                                                2,
                                                                                ( UCHAR**) &psi2
                                                                           )
                                        )
          )
          {
               lstrcpyn     (     pwszLocalName,     psi2->shi2_path,     dwSize);

               NetApiBufferFree     (     psi2);

               return     (     nas);
          }

     return     (     nas);
}


int     Usage     ()
{
     wprintf     (     L"Usage:\tshrlocal <network share>\n\n");

     return     (     -1);
}

int     wmain     (     int               argc,    
                    wchar_t**     argv
               )
{
     NET_API_STATUS     nas;

     wchar_t               awcLocal     [     MAX_PATH] = L"\0";


     if     (     2     !=     argc)     return     (     Usage     ());

     nas     =     GetShareLocalName     (      argv [ 1],     awcLocal,     MAX_PATH);

     if     (     NERR_Success     ==     nas)
               wprintf     (     L"\nNetName:\t%s\nLocalName:\t%s\n",    
                              argv     [ 1],    
                              awcLocal
                         );
      else
               wprintf     (     L"\nERROR: %d\n",     nas);

     return     (     0);
}
0
 
LVL 32

Expert Comment

by:jhance
ID: 6972074
Uh-oh!  The dreaded "no text" bug has reappeared!!!  Arghhhh.
0
 
LVL 32

Expert Comment

by:jhance
ID: 6972082
Yes, you are right.  I misunderstood the question.

I thought he was asking for the LOCAL PATH on the workstation where the app was running.  That would not necessarily be there if the remote path was not mapped to a local drive letter.  But after reading the question I see that your interpretation is probably the intent of the question.

0
 

Author Comment

by:masvmasv
ID: 6972167
Thanks...

The NetShareGetInfo is my solution...

Thanks
0

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

618 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