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
Solved

Get a real path from a network shared

Posted on 2002-04-26
9
362 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
  • 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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 100 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

856 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