-
How to determine path of virtual drive
How does one determine, programmatically, what the path is that a virtual drive maps to?
The virtual drive is set up using subst.exe.
TIA,
Peter Young
-
Re: How to determine path of virtual drive
"Peter Young" <pyoung0spam@phoenixdsl.com> skrev i meddelandet
news:3a19b897@news.devx.com...
> How does one determine, programmatically, what the path is that a virtual
drive maps to?
>
> The virtual drive is set up using subst.exe.
>
> TIA,
>
> Peter Young
>
>
Not sure about subst, but the code below (stolen from somewhere) will
convert any networked drive to UNC...
Put this in a .bas module:
----------------------------------------------------------------------------
----------------------------
Public Declare Function WNetGetConnection Lib "mpr.dll" Alias
"WNetGetConnectionA" _
(ByVal lpszLocalName As String, _
ByVal lpszRemoteName As String, _
cbRemoteName As Long) As Long
Public Const NO_ERROR = 0
Public Const ERROR_BAD_DEVICE = 1200&
Public Const ERROR_NOT_CONNECTED = 2250&
Public Const ERROR_MORE_DATA = 234
Public Const ERROR_CONNECTION_UNAVAIL = 1201&
Public Const ERROR_NO_NETWORK = 1222&
Public Const ERROR_EXTENDED_ERROR = 1208&
Public Const ERROR_NO_NET_OR_BAD_PATH = 1203&
----------------------------------------------------------------------------
--------------------------
This is the actual function:
Public Function DriveLetterToUNC(ByVal DriveLetter As String) As String
Dim nRet As Long
Dim Drv As String
Dim Buffer As String
Dim BufLen As Long
Const MAX_PATH = 260
Dim ErrMsg$, ErrNum%
If Len(DriveLetter) Then
' massage input string and create buffer
Drv = UCase(Left(DriveLetter, 1)) & ":"
Buffer = Space(MAX_PATH)
BufLen = Len(Buffer)
' attempt to get UNC info
nRet = WNetGetConnection(Drv, Buffer, BufLen)
If nRet = ERROR_MORE_DATA Then ' increase buffer and call again
Buffer = Space(BufLen)
nRet = WNetGetConnection(Drv, Buffer, BufLen)
End If
If nRet = NO_ERROR Then
' return UNC name by trimming at first null
DriveLetterToUNC = Left(Buffer, InStr(Buffer, vbNullChar) - 1)
Else
Select Case nRet
Case ERROR_BAD_DEVICE
ErrMsg = Drv & " is invalid"
Case ERROR_NOT_CONNECTED
ErrMsg = Drv & " This network connection does not
exist."
Case ERROR_CONNECTION_UNAVAIL
ErrMsg = Drv & " The device is not currently connected
but it is a remembered connection."
Case ERROR_NO_NETWORK
ErrMsg = "DriveLetterToUNC: The network is not present
or not started."
Case ERROR_MORE_DATA
ErrMsg = "DriveLetterToUNC: Buffer is too small!"
Case ERROR_EXTENDED_ERROR
ErrMsg = "DriveLetterToUNC: An error has occurred, call
WNetGetLastError."
Case Else
ErrMsg = "DriveLetterToUNC: Unknown error code: " & nRet
End Select
Err.Raise vbObjectError + nRet, Err.Source, ErrMsg
End If
End If
End Function
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks