Foros del Web » Programación para mayores de 30 ;) » Programación General »

Saber el nombre de las unidades compartidas

Estas en el tema de Saber el nombre de las unidades compartidas en el foro de Programación General en Foros del Web. Buenas! tengo la siguiente duda... He creado una aplicacion que es un simple menu (en access) que abre otras aplicaciones tambien de access. Los archivos ...
  #1 (permalink)  
Antiguo 28/09/2010, 05:43
 
Fecha de Ingreso: septiembre-2010
Mensajes: 26
Antigüedad: 13 años, 6 meses
Puntos: 0
Saber el nombre de las unidades compartidas

Buenas! tengo la siguiente duda...
He creado una aplicacion que es un simple menu (en access) que abre otras aplicaciones tambien de access.
Los archivos access que abro estan en unidades de red compartidas, el caso es que en mi equipo el nombre de la unidad es Z y en otros es Y, por lo que en algunos equipos no funciona...

como podria evitar tener q indicar el numero de la unidad??

si por ejemplo la ruta en mi pc fuera

z:\carpeta\archivo.txt

y en otro fuera

y:\carpeta\archivo.txt

en mi codigo que tendria que poner??

..\carpeta\archivo.txt no funciona...

He encontrado este codigo pero no estoy seguro de como funciona...si alguien me puede comentar...se lo agradeceria muchisimoooo!!


Private Const RESOURCETYPE_ANY = &H0
Private Const RESOURCE_CONNECTED = &H1
Private Type NETRESOURCE
dwScope As Long
dwType As Long
dwDisplayType As Long
dwUsage As Long
lpLocalName As Long
lpRemoteName As Long
lpComment As Long
lpProvider As Long
End Type
Private Declare Function WNetOpenEnum Lib "mpr.dll" Alias "WNetOpenEnumA" (ByVal dwScope As Long, ByVal dwType As Long, ByVal dwUsage As Long, lpNetResource As Any, lphEnum As Long) As Long
Private Declare Function WNetEnumResource Lib "mpr.dll" Alias "WNetEnumResourceA" (ByVal hEnum As Long, lpcCount As Long, lpBuffer As Any, lpBufferSize As Long) As Long
Private Declare Function WNetCloseEnum Lib "mpr.dll" (ByVal hEnum As Long) As Long
Private Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" (ByVal lpString As Any) As Long
Private Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" (ByVal lpString1 As Any, ByVal lpString2 As Any) As Long
Function LetterToUNC(DriveLetter As String) As String
Dim hEnum As Long
Dim NetInfo(1023) As NETRESOURCE
Dim entries As Long
Dim nStatus As Long
Dim LocalName As String
Dim UNCName As String
Dim i As Long
Dim r As Long

' Begin the enumeration
nStatus = WNetOpenEnum(RESOURCE_CONNECTED, RESOURCETYPE_ANY, 0&, ByVal 0&, hEnum)

LetterToUNC = DriveLetter

'Check for success from open enum
If ((nStatus = 0) And (hEnum <> 0)) Then
' Set number of entries
  #2 (permalink)  
Antiguo 28/09/2010, 05:44
 
Fecha de Ingreso: septiembre-2010
Mensajes: 26
Antigüedad: 13 años, 6 meses
Puntos: 0
Respuesta: Saber el nombre de las unidades compartidas

EL codigo completo:
Private Const RESOURCETYPE_ANY = &H0
Private Const RESOURCE_CONNECTED = &H1
Private Type NETRESOURCE
dwScope As Long
dwType As Long
dwDisplayType As Long
dwUsage As Long
lpLocalName As Long
lpRemoteName As Long
lpComment As Long
lpProvider As Long
End Type
Private Declare Function WNetOpenEnum Lib "mpr.dll" Alias "WNetOpenEnumA" (ByVal dwScope As Long, ByVal dwType As Long, ByVal dwUsage As Long, lpNetResource As Any, lphEnum As Long) As Long
Private Declare Function WNetEnumResource Lib "mpr.dll" Alias "WNetEnumResourceA" (ByVal hEnum As Long, lpcCount As Long, lpBuffer As Any, lpBufferSize As Long) As Long
Private Declare Function WNetCloseEnum Lib "mpr.dll" (ByVal hEnum As Long) As Long
Private Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" (ByVal lpString As Any) As Long
Private Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" (ByVal lpString1 As Any, ByVal lpString2 As Any) As Long
Function LetterToUNC(DriveLetter As String) As String
Dim hEnum As Long
Dim NetInfo(1023) As NETRESOURCE
Dim entries As Long
Dim nStatus As Long
Dim LocalName As String
Dim UNCName As String
Dim i As Long
Dim r As Long

' Begin the enumeration
nStatus = WNetOpenEnum(RESOURCE_CONNECTED, RESOURCETYPE_ANY, 0&, ByVal 0&, hEnum)

LetterToUNC = DriveLetter

'Check for success from open enum
If ((nStatus = 0) And (hEnum <> 0)) Then
' Set number of entries
entries = 1024

' Enumerate the resource
nStatus = WNetEnumResource(hEnum, entries, NetInfo(0), CLng(Len(NetInfo(0))) * 1024)

' Check for success
If nStatus = 0 Then
For i = 0 To entries - 1
' Get the local name
LocalName = ""
If NetInfo(i).lpLocalName <> 0 Then
LocalName = Space(lstrlen(NetInfo(i).lpLocalName) + 1)
r = lstrcpy(LocalName, NetInfo(i).lpLocalName)
End If

' Strip null character from end
If Len(LocalName) <> 0 Then
LocalName = Left(LocalName, (Len(LocalName) - 1))
End If

If UCase$(LocalName) = UCase$(DriveLetter) Then
' Get the remote name
UNCName = ""
If NetInfo(i).lpRemoteName <> 0 Then
UNCName = Space(lstrlen(NetInfo(i).lpRemoteName) + 1)
r = lstrcpy(UNCName, NetInfo(i).lpRemoteName)
End If

' Strip null character from end
If Len(UNCName) <> 0 Then
UNCName = Left(UNCName, (Len(UNCName) - 1))
End If

' Return the UNC path to drive
'added the [] to seperate on printout only
LetterToUNC = UNCName

' Exit the loop
Exit For
End If
Next i
End If
End If

' End enumeration
nStatus = WNetCloseEnum(hEnum)
End Function
Private Sub Form_Load()
'KPD-Team 1999
'URL: http://www.allapi.net/
'E-Mail: [email protected]
'-> This sample was created by Donald Grover
MsgBox "C: UNC path: " + LetterToUNC("C:")
End Sub

Etiquetas: nombre, unidad
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 17:00.