?
Solved

Get a real path from a network shared

Posted on 2002-04-26
9
Medium Priority
?
365 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

765 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