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

Saber el nombre de mi PC y nombre de unidades compartidas

Estas en el tema de Saber el nombre de mi PC y nombre de unidades compartidas en el foro de Programación General en Foros del Web. Hola, Así como se logra con el control "DriveListBox" ... ¿Existirá alguna forma de obtener el nombre de las unidades compartidas en la red? Por ...
  #1 (permalink)  
Antiguo 18/03/2003, 07:26
(Desactivado)
 
Fecha de Ingreso: noviembre-2002
Mensajes: 124
Antigüedad: 21 años, 5 meses
Puntos: 0
Saber el nombre de mi PC y nombre de unidades compartidas

Hola,

Así como se logra con el control "DriveListBox" ... ¿Existirá alguna forma de obtener el nombre de las unidades compartidas en la red?

Por ejemplo, la unidad C: de mi PC puede ser vista como Z: por otros equipos conectados, si ese es el nombre compartido.

Por otro lado, ¿alguien tendrá un código que me permita recuperar el mombre de mi PC? Es decir, el nombre que se da en "Identificación" del panel "Entorno de red" y es el nombre con el que se conoce mi PC en toda la red.

Por favor, debe ser en Visual Basic.

¿Muy dificil?

Bueno, esto es para los que saben de esto, gracias.
  #2 (permalink)  
Antiguo 19/03/2003, 13:50
Avatar de Jorge_Mota  
Fecha de Ingreso: diciembre-2002
Ubicación: Chapinlandia :-D
Mensajes: 725
Antigüedad: 21 años, 5 meses
Puntos: 11
tomado de allapi.net

'To run this program, you must set the startup object to 'Sub Main'
'You can do this by going to Project->Project Properties->Startup Object
'In a module
Private Const PLATFORM_ID_DOS = 300
Private Const PLATFORM_ID_OS2 = 400
Private Const PLATFORM_ID_NT = 500
Private Const PLATFORM_ID_OSF = 600
Private Const PLATFORM_ID_VMS = 700

Private Type WKSTA_INFO_102
wki100_platform_id As Long
pwki100_computername As Long
pwki100_langroup As Long
wki100_ver_major As Long
wki100_ver_minor As Long
pwki102_lanroot As Long
wki102_logged_on_users As Long
End Type

Declare Function NetWkstaGetInfo Lib "netapi32" (ByVal servername As String, ByVal level As Long, lpBuf As Any) As Long
Declare Function NetApiBufferFree Lib "netapi32" (ByVal Buffer As Long) As Long
Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, ByVal hpvSource As Long, ByVal cbCopy As Long)
Sub Main()
'code submitted by Andreas Linnemann ([email protected])
Dim pWrkInfo As Long, WrkInfo(0) As WKSTA_INFO_102, lResult As Long
'make sure you replace the value of the following constant
'with a valid computer name from your LAN
Const strComputername = "YourComputerName"
lResult = NetWkstaGetInfo(StrConv("\\" & strComputername, vbUnicode), 102, pWrkInfo)
If lResult = 0 Then
Dim cname As String
cname = String$(255, 0)
CopyMemory WrkInfo(0), ByVal pWrkInfo, ByVal Len(WrkInfo(0))
CopyMemory ByVal cname, ByVal WrkInfo(0).pwki100_langroup, ByVal 255
Debug.Print "Domain: " & StripTerminator(StrConv(cname, vbFromUnicode))
Debug.Print "Operating System: ";
Select Case WrkInfo(0).wki100_platform_id
Case PLATFORM_ID_DOS: Debug.Print "DOS"
Case PLATFORM_ID_OS2:
If WrkInfo(0).wki100_ver_major = "4" Then
Debug.Print "Win9x"
Else
Debug.Print "OS2"
End If
Case PLATFORM_ID_NT:
If WrkInfo(0).wki100_ver_major = "5" Then
Debug.Print "Win 2000"
Else
Debug.Print "Win NT"
End If
Case PLATFORM_ID_OSF: Debug.Print "OSF"
Case PLATFORM_ID_VMS: Debug.Print "VMS"
End Select
Debug.Print " Version "; WrkInfo(0).wki100_ver_major; "."; WrkInfo(0).wki100_ver_minor
Debug.Print "Lan Root: ";
cname = String$(255, 0)
CopyMemory ByVal cname, ByVal WrkInfo(0).pwki102_lanroot, ByVal 255
Debug.Print StripTerminator(StrConv(cname, vbFromUnicode))
Debug.Print "Logged User: "; Str$(WrkInfo(0).wki102_logged_on_users), vbBlack
NetApiBufferFree ByVal pWrkInfo
End If
End Sub
'This function is used to stripoff all the unnecessary chr$(0)'s
Private Function StripTerminator(sInput As String) As String
Dim ZeroPos As Integer
'Search the first chr$(0)
ZeroPos = InStr(1, sInput, vbNullChar)
If ZeroPos > 0 Then
StripTerminator = Left$(sInput, ZeroPos - 1)
Else
StripTerminator = sInput
End If
End Function
__________________
Jorge Mota
Blog
Gubiz estafa
  #3 (permalink)  
Antiguo 19/03/2003, 13:51
Avatar de Jorge_Mota  
Fecha de Ingreso: diciembre-2002
Ubicación: Chapinlandia :-D
Mensajes: 725
Antigüedad: 21 años, 5 meses
Puntos: 11
esto para ver lo de las redes, revisalo aver si es lo que necesitas
tambien de www.allapi.net.
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
__________________
Jorge Mota
Blog
Gubiz estafa
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 14:36.