Solved

Get a real path from a network shared

Posted on 2002-04-26
9
357 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
 
LVL 86

Expert Comment

by:jkr
ID: 6972067
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

757 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now