Solved

Get a real path from a network shared

Posted on 2002-04-26
9
363 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
Independent Software Vendors: 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 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Suggested Solutions

Title # Comments Views Activity
ASP.net build a IF/Then Walkthrough Guide 1 283
C++ Language error 28 281
c++ using a LPCOLESTR * and adding a string varaible to the Pointer 2 76
Need some help with mailto 16 34
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…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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…

696 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