Solved

DirListBox, DriveListBox, FileListBox Controls

Posted on 2000-05-12
6
1,264 Views
Last Modified: 2012-06-21
I've got these three controls on a form in VB6.  When I select a file in the FileListBox, I need to be able to extract the UNC path of the file (i.e. \\server\share\filename.txt) and NOT the drive-letter specified path (i.e. F:\share\filename.txt).

I'm trying to feed command-line parameters to a command-line utility from a GUI VB application.  I need to "feed" the command-line program the full UNC path in the form of a string appended to the end of the command (for example, myprog.exe "\\server\share\file.txt").
0
Comment
Question by:Zoplax
[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
  • 4
6 Comments
 
LVL 9

Expert Comment

by:GivenRandy
ID: 2805409
Use API WNetGetConnection:

Declare Function WNetGetConnection Lib "mpr.dll" Alias _
  "WNetGetConnectionA" (ByVal lpszLocalName As String, _
  ByVal lpszRemoteName As String, cbRemoteName As Long) As Long

It will return the UNC path for a map network drive in lpszRemoteName (pass the Drive: to lpszLocalName). For local drive it will return WN_NOT_CONNECTED (2250&).


0
 
LVL 9

Expert Comment

by:GivenRandy
ID: 2805417
A more detailed response:

Public Const ERROR_BAD_DEVICE = 1200&
Public Const ERROR_CONNECTION_UNAVAIL = 1201&
Public Const ERROR_EXTENDED_ERROR = 1208&
Public Const ERROR_MORE_DATA = 234 '  dderror
Public Const ERROR_NOT_SUPPORTED = 50&
Public Const ERROR_NO_NET_OR_BAD_PATH = 1203&
Public Const ERROR_NO_NETWORK = 1222&
Public Const ERROR_NOT_CONNECTED = 2250&

Public Const UNIVERSAL_NAME_INFO_LEVEL = &H00000001&
Public Const REMOTE_NAME_INFO_LEVEL = &H00000002&

Declare Function WNetGetUniversalName Lib "mpr" Alias "WNetGetUniversalNameA" (ByVal lpLocalPath As String, ByVal dwInfoLevel As Long, lpBuffer As Any, lpBufferSize As Long) As Long

Here is an explanation:

The WNetGetUniversalName function takes a drive-based path for a network resource and obtains a data structure that contains a more universal form of the name.
DWORD WNetGetUniversalName(
    LPCTSTR lpLocalPath, // pointer to drive-based path for a network resource
    DWORD dwInfoLevel, // specifies form of universal name to be obtained
    LPVOID lpBuffer, // pointer to buffer that receives universal name data structure
    LPDWORD lpBufferSize // pointer to variable that specifies size of buffer
   );
 
Parameters
lpLocalPath
Points to a null-terminated string that is a drive-based path for a network resource.
For example, if drive H has been mapped to a network drive share, and the network resource of interest is a file named SAMPLE.DOC in the directory \WIN32\EXAMPLES on that share, the drive-based path is H:\WIN32\EXAMPLES\SAMPLE.DOC.
dwInfoLevel
Specifies the type of data structure that the function will store in the buffer pointed to by lpBuffer. This parameter can be one of the following values:
Value Meaning
UNIVERSAL_NAME_INFO_LEVEL The function will store a UNIVERSAL_NAME_INFO data structure in the buffer.
REMOTE_NAME_INFO_LEVEL_ The function will store a REMOTE_NAME_INFO data structure in the buffer.
 
The UNIVERSAL_NAME_INFO data structure points to a Universal Naming Convention (UNC) name string.
lpBuffer
Points to a buffer that receives the type of data structure specified by the dwInfoLevel parameter.
lpBufferSize
Points to a variable that specifies the size in bytes of the buffer pointed to by lpBuffer.
If the function succeeds, it sets the variable pointed to by lpBufferSize to the size in bytes of the data structure stored in the buffer. If the function fails because the buffer is too small, indicated by the ERROR_MORE_DATA error code, it sets the variable pointed to by lpBufferSize to the required buffer size.
 
Return Values
If the function succeeds, the return value is NO_ERROR.
If the function fails, the return value is an error code. To get extended error information, call GetLastError. GetLastError may return one of the following error codes:
Value Meaning
ERROR_BAD_DEVICE The string pointed to by lpLocalPath is invalid.
ERROR_CONNECTION_UNAVAIL There is no current connection to the remote device, but there is a remembered (persistent) connection to it.
ERROR_EXTENDED_ERROR A network-specific error occurred. Use the WNetGetLastError function to obtain a description of the error.
ERROR_MORE_DATA The buffer pointed to by lpBuffer is too small. The function sets the variable pointed to by lpBufferSize to the required buffer size.
ERROR_NOT_SUPPORTED The dwInfoLevel parameter was set to UNIVERSAL_NAME_INFO_LEVEL, but the network provider does not support UNC  names. This function is not supported by any of the network providers.
ERROR_NO_NET_OR_BAD_PATH None of the providers recognized this local name as having a connection. However, the network is not available for at least one provider to whom the connection may belong.
ERROR_NO_NETWORK There is no network present.
ERROR_NOT_CONNECTED The device specified by lpLocalPath is not redirected.
 
Remarks
A universal form of a local drive-based path identifies a network resource in an unambiguous, computer-independent manner. The name can then be passed to processes on other computers, allowing those processes to obtain access to the resource.
The WNetGetUniversalName function currently supports one universal name form: universal naming convention (UNC) names, which look like the following:
\\servername\sharename\path\file  
 
Using the example from the preceding description of the lpLocalPath parameter, if the shared network drive is on a server named COOLSERVER, and the share name is HOTSHARE, the UNC name for the network resource whose drive-based name is H:\WIN32\EXAMPLES\SAMPLE.DOC would be
\\coolserver\hotshare\win32\examples\sample.doc  
 
The UNIVERSAL_NAME_INFO data structure contains a pointer to a UNC name string. The REMOTE_NAME_INFO data structure contains a pointer to a UNC name string. It also includes pointers to two other useful strings. A process can pass the REMOTE_NAME_INFO structure's lpszConnectionInfo member into the WNetAddConnection2 function to connect a local device to the network resource, and then append the string pointed to by the lpszRemainingPath member to the local device string. The resulting string can be passed to Win32 functions that use a drive-based path.
0
 
LVL 9

Expert Comment

by:GivenRandy
ID: 2805442
Another option is to add a hidden DriveListBox.  When a file is selected, use the drive in DriveListBoxand get the UNC from it.  Just set the Drive property and then read it.  For example:

Drive1.Drive = "h:\"
MsgBox Drive1.Drive
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 28

Expert Comment

by:AzraSound
ID: 2805450
HOWTO: Get UNC Path From a Mapped Network Share's Drive Letter


http://support.microsoft.com/support/kb/articles/Q192/6/89.asp
0
 
LVL 9

Accepted Solution

by:
GivenRandy earned 50 total points
ID: 2805457
Another option is to add a hidden DriveListBox.  When a file is selected, use the drive in DriveListBoxand get the UNC from it.  Just set the Drive property and then read it.  For example:

Drive1.Drive = File1.Path
MsgBox Drive1.Drive

The Drive property may have brackets around the UNC value, which you can trim.
0
 
LVL 6

Author Comment

by:Zoplax
ID: 2805615
Excellent, thanks GivenRandy for your details and examples!

Also thanks AzraSound for finding that link on Micro$oft's site, I'll check that out as well.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

752 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