ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Help WNetGetUniversalName ... in vba (https://www.excelbanter.com/excel-programming/295688-help-wnetgetuniversalname-vba.html)

Joao Rodrigues

Help WNetGetUniversalName ... in vba
 
Can anyone tell me why this doesn't work ?

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

Type UUU
UU As String
End Type


Public Sub AA()
Dim CC As UUU
Dim TT As Long
Dim kk As Long
kk = WNetGetUniversalName("H:\", 1, CC, TT)
If TT 0 Then
MsgBox TT
MsgBox CC.UU
End If
kk = WNetGetUniversalName("H:\", 2, CC, TT)
If TT 0 Then
MsgBox TT
MsgBox CC.UU
End If
End Sub

the problem is that CC always "stay" empty

H: is a share in a server...

what i want to know is the name of the server and share...

Thanks in advance

Joćo Rodrigues



Rob Bovey

Help WNetGetUniversalName ... in vba
 
Hi Joao,

Here's a working example of WNetGetUniversalNameA:

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

Public Sub GetUNCPath()

Dim bytBuffer(1 To 256) As Byte
Dim lReturn As Long
Dim szPath As String

lReturn = WNetGetUniversalNameA("H:\", 1, bytBuffer(1), 256)

If lReturn = 0 Then
szPath = StrConv(bytBuffer, vbUnicode)
szPath = Left$(szPath, InStr(szPath, vbNullChar) - 1)
szPath = Right$(szPath, Len(szPath) - 4)
Debug.Print szPath
Else
MsgBox "Error getting UNC path.", vbCritical
End If

End Sub

The WNetGetConnection API is a lot simpler if all you want to get is the
UNC equivalent of a mapped drive:

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

Public Sub GetUNCPath()

Dim lReturn As Long
Dim szBuffer As String

szBuffer = String$(256, vbNullChar)
lReturn = WNetGetConnectionA("Z:", szBuffer, 256)

If lReturn = 0 Then
Debug.Print Left$(szBuffer, InStr(szBuffer, vbNullChar))
Else
MsgBox "Error getting UNC path.", vbCritical
End If

End Sub

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *


"Joao Rodrigues" wrote in message
...
Can anyone tell me why this doesn't work ?

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

Type UUU
UU As String
End Type


Public Sub AA()
Dim CC As UUU
Dim TT As Long
Dim kk As Long
kk = WNetGetUniversalName("H:\", 1, CC, TT)
If TT 0 Then
MsgBox TT
MsgBox CC.UU
End If
kk = WNetGetUniversalName("H:\", 2, CC, TT)
If TT 0 Then
MsgBox TT
MsgBox CC.UU
End If
End Sub

the problem is that CC always "stay" empty

H: is a share in a server...

what i want to know is the name of the server and share...

Thanks in advance

Joćo Rodrigues




Joao Rodrigues

Help WNetGetUniversalName ... in vba
 
Both solutions are what i was looking for.

Thank you sir.

Joao Rodrigues
-----Original Message-----
Hi Joao,

Here's a working example of WNetGetUniversalNameA:

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

Public Sub GetUNCPath()

Dim bytBuffer(1 To 256) As Byte
Dim lReturn As Long
Dim szPath As String

lReturn = WNetGetUniversalNameA("H:\", 1, bytBuffer

(1), 256)

If lReturn = 0 Then
szPath = StrConv(bytBuffer, vbUnicode)
szPath = Left$(szPath, InStr(szPath, vbNullChar) -

1)
szPath = Right$(szPath, Len(szPath) - 4)
Debug.Print szPath
Else
MsgBox "Error getting UNC path.", vbCritical
End If

End Sub

The WNetGetConnection API is a lot simpler if all you

want to get is the
UNC equivalent of a mapped drive:

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

Public Sub GetUNCPath()

Dim lReturn As Long
Dim szBuffer As String

szBuffer = String$(256, vbNullChar)
lReturn = WNetGetConnectionA("Z:", szBuffer, 256)

If lReturn = 0 Then
Debug.Print Left$(szBuffer, InStr(szBuffer,

vbNullChar))
Else
MsgBox "Error getting UNC path.", vbCritical
End If

End Sub

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *


"Joao Rodrigues"

wrote in message
...
Can anyone tell me why this doesn't work ?

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

Type UUU
UU As String
End Type


Public Sub AA()
Dim CC As UUU
Dim TT As Long
Dim kk As Long
kk = WNetGetUniversalName("H:\", 1, CC, TT)
If TT 0 Then
MsgBox TT
MsgBox CC.UU
End If
kk = WNetGetUniversalName("H:\", 2, CC, TT)
If TT 0 Then
MsgBox TT
MsgBox CC.UU
End If
End Sub

the problem is that CC always "stay" empty

H: is a share in a server...

what i want to know is the name of the server and share...

Thanks in advance

Joćo Rodrigues



.



All times are GMT +1. The time now is 02:07 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com