Solved

networkpath

Posted on 1998-01-28
11
177 Views
Last Modified: 2012-06-27
Hi,

I'm trying to store the full network path of a file in a shared directory network into a database, so that other users using the same database can call up this documet from anywhere in the network. I suppose there is a Windows API to retrieve the full network path a file. Does anybody know which one and how to use it ?

Thanks,
Rudi.
0
Comment
Question by:rudi_huysmans
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 32

Expert Comment

by:jhance
Comment Utility
To get the full network pathname to a file you have to start with something.  What do you have to start with?
0
 

Author Comment

by:rudi_huysmans
Comment Utility
I currently have the complete drivename + path + filename. This might also be on a networkdrive using a mapped directory. (ex. C:\My Documents\document.doc or L:\docs\document.doc).
0
 

Author Comment

by:rudi_huysmans
Comment Utility
Adjusted points to 400
0
 
LVL 5

Expert Comment

by:inter
Comment Utility
I feel that I know the answer but I should ask some questions:

1 - What is your OS?
2 - Is the following explains what you want to do:
    You have a document server A (computername) and there is a file on that (e.g. c:\dir1\dir2\test.doc'). There are other computers in the network named B, C, ...etc. You share the c:\dir1\dir2 as for example 'AShare'. Say all the other computers maps it as for example 'F:'. Now:

i - Do you want to store 'F:\test.doc' in database and from it restore c:\dir1\dir2\test.doc?
ii- Or you want to store 'c:\dir1\dir2\test.doc' so that you retreive 'F:\test.doc'

Please notify,

Igor

0
 
LVL 1

Expert Comment

by:hustch
Comment Utility
On Windows NT you can use WNetGetUniversalName

DWORD WNetGetUniversalName(

    LPCTSTR  lpLocalPath,      // address of drive-based path for a network resource
    DWORD  dwInfoLevel,      // specifies form of universal name to be obtained
    LPVOID  lpBuffer,      // address of buffer that receives universal name data structure
    LPDWORD  lpBufferSize       // address of variable that specifies size of buffer
   );      

See the Win32
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:rudi_huysmans
Comment Utility
Hello,

thank you for your answer but the operating system I'm programming for is Windows '95.
I did try the function (you never now with MS) but it didn't work in '95.

I'll give some more details about the question:
OS: WIN '95
What I'm trying to do is something like this:
There's a document on the server in \dir1\documents\doc1.txt.
When a user selects this file it would probably look to him like L:\documents\doc1.txt. L is actually mapped to the directory on the server. This has to be translated into \\ServerName\documents\doc1.txt assuming that the server is named ServerName.
I did find such a function in WordBasic named fileInfo. But I can't rely on the fact that Word is installed to used this.

0
 
LVL 1

Expert Comment

by:hustch
Comment Utility
I know, it doesn't work under Windows 95
I'll try to find a solution for 95, but I won't have time before at the end ot this week.
0
 
LVL 5

Expert Comment

by:inter
Comment Utility
Dear rudi_huysmans,

The function that both works on NT and 95 is WNetGetConnection exported from mpr.dll(when you search for it from findfiles containing WNetGetConnection it is in system directory for win95), here is the script to retreive the actual network path of a device:

  char remote[255], local[255];
  DWORD len;

  strcpy(remote, "L:");
  len = sizeof(remote);
  if ((WNetGetConnection(local, remote, len) == NO_ERROR) {
     // the remote now contains e.g. \\servername\dir1\dir2
     // so just append the path after L: e.g. \documents
  }

Tell me if it helps
Igor
0
 
LVL 5

Expert Comment

by:inter
Comment Utility
Sorry the call should be

WNetGetConnection(&local, &remote, &len)
0
 
LVL 2

Accepted Solution

by:
AlFa earned 400 total points
Comment Utility
Perhaps Ms has the answer

The functionality provided by WNetGetUniversalName can be implemented using the Win32 network enumeration functions WNetOpenEnum and WNetEnumResource. Here is an example of how to use these functions to implement similar functionality:


   #include <windows.h>
   #include <stdio.h>

   // Function Name:  GetUniversalName
   //
   // Parameters:     szUniv  - contains the UNC equivalent of szDrive
   //                           upon completion
   //
   //                 szDrive - contains a drive based path
   //
   // Return value:   TRUE if successful, otherwise FALSE
   //
   // Comments:       This function assumes that szDrive contains a
   //                 valid drive based path.
   //
   //                 For simplicity, this code assumes szUniv points
   //                 to a buffer large enough to accommodate the UNC
   //                 equivalent of szDrive.

   BOOL GetUniversalName( char szUniv[], char szDrive[] )
   {
      // get the local drive letter
      char chLocal = toupper( szDrive[0] );

      // cursory validation
      if ( chLocal < 'A' || chLocal > 'Z' )
         return FALSE;

      if ( szDrive[1] != ':' || szDrive[2] != '\\' )
         return FALSE;

      HANDLE hEnum;
      DWORD dwResult = WNetOpenEnum( RESOURCE_CONNECTED, RESOURCETYPE_DISK,
                                     0, NULL, &hEnum );

      if ( dwResult != NO_ERROR )
         return FALSE;

      // request all available entries
      const int    c_cEntries   = 0xFFFFFFFF;
      // start with a reasonable buffer size
      DWORD        cbBuffer     = 50 * sizeof( NETRESOURCE );
      NETRESOURCE *pNetResource = (NETRESOURCE*) malloc( cbBuffer );

      BOOL fResult = FALSE;

      while ( TRUE )
      {
         DWORD dwSize   = cbBuffer,
               cEntries = c_cEntries;

         dwResult = WNetEnumResource( hEnum, &cEntries, pNetResource,
                                      &dwSize );

         if ( dwResult == ERROR_MORE_DATA )
         {
            // the buffer was too small, enlarge
            cbBuffer = dwSize;
            pNetResource = (NETRESOURCE*) realloc(pNetResource, cbBuffer);
            continue;
         }

         if ( dwResult != NO_ERROR )
            goto done;

         // search for the specified drive letter
         for ( int i = 0; i < (int) cEntries; i++ )
            if ( pNetResource[i].lpLocalName &&
                 chLocal == toupper(pNetResource[i].lpLocalName[0]) )
            {
               // match
               fResult = TRUE;

               // build a UNC name
               strcpy( szUniv, pNetResource[i].lpRemoteName );
               strcat( szUniv, szDrive + 2 );
               _strupr( szUniv );
               goto done;
            }
      }

   done:
      // cleanup
      WNetCloseEnum( hEnum );
      free( pNetResource );

      return fResult;

   }

alain,
0
 

Author Comment

by:rudi_huysmans
Comment Utility
Thank you, AlFa.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

  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 …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

762 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

10 Experts available now in Live!

Get 1:1 Help Now