Newsgroup: it.comp.lang.visual-basic
Titolo: Scusate l'insistenza ma ho un po d'urgenza (Rete)

Salve a tutti,
mi servirebbe un aiuto su per un'applicazione che sto scrivendo.
Il problema è questo vorrei creare dell'option button in run-time che come
caption hanno il nome dei computer in rete.
Riesco a creare le option button ma non riesco a vedere la rete già
presente.
Grazioe a tutti
Shiryu
--------------------------------
Inviato via 
http://usenet.libero.it

 Shiryu
Vuoi il sorgente o preferisci l'eseguibile? :))

 ha scritto


Se è possibile il sorgente, te ne saro eternamente grato


 ha scritto nel messaggio
news:195Z110Z141Z52Y...@usenet.libero.it...

hihihi Mi sa che la risposta aveva un tono sarcastico!!!
--
Ciao
   Sharkman
-----------------------------
Rimuovere NOSPAM per risposte

 Grazioe a tutti
Avevo risolto la cosa utilizzando gli oggetti della libreria shell32
salutoni
Sergio

 Sergio
Ti dispiacerebbe dirmi come non sono molto pratico delle librerie shell32


 Ti dispiacerebbe dirmi come non sono molto pratico delle librerie shell32
ehm.. neanche io lo ero prima di leggere l'help....e adesso credo di non
esserlo piů, visto che le ho utilizzate piů di un anno fa (era un piccolo
applicativo che spazzolava i computer di una intranet in cerca di
condivisioni nascoste sui drive, cercava i c$ insomma, per individuare
quelli nfettati da nimda, visto che ero stufo di trovare i pc impestati)
Mi sembra di ricordare che MSDN in merito, pur essendo completa non fosse
chiarissima, ma al momento piů di questo consiglio non so/posso darti.
Salutoni
Sergio

 Inviato via 
http://usenet.libero.it
da qui copia e incolla in un file di testo, chiamalo come ti pare con
estenZione frm, crea un progetto in VB ed aggiungici questo form; non mi
chiedere nulla perché non so nulla... bye...
###############
VERSION 5.00
Begin VB.Form netUser
   AutoRedraw      =   -1  'True
   Caption         =   "Form1"
   ClientHeight    =   4092
   ClientLeft      =   1164
   ClientTop       =   1392
   ClientWidth     =   4128
   BeginProperty Font
      Name            =   "Tahoma"
      Size            =   7.2
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   LinkTopic       =   "Form1"
   ScaleHeight     =   4092
   ScaleWidth      =   4128
   Begin VB.ListBox rEle3
      Appearance      =   0  'Flat
      Height          =   3504
      IntegralHeight  =   0   'False
      Left            =   1224
      TabIndex        =   3
      Top             =   360
      Width           =   1740
   End
   Begin VB.ListBox rEle2
      Appearance      =   0  'Flat
      Height          =   3504
      IntegralHeight  =   0   'False
      Left            =   2988
      TabIndex        =   2
      Top             =   360
      Width           =   1056
   End
   Begin VB.CommandButton Command1
      Caption         =   "list computers..."
      Height          =   300
      Left            =   72
      TabIndex        =   1
      Top             =   36
      Width           =   3972
   End
   Begin VB.ListBox rEle1
      Appearance      =   0  'Flat
      Height          =   3504
      IntegralHeight  =   0   'False
      Left            =   72
      TabIndex        =   0
      Top             =   360
      Width           =   1164
   End
End
Attribute VB_Name = "netUser"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private OldStatus As Integer
'Add this code to a module and set the Project's Startup Object to 'Sub
Main'
'    (-> Project Menu -> Project Properties -> General Tab)
Private Const RESOURCE_CONNECTED As Long = &H1&
Private Const RESOURCE_GLOBALNET As Long = &H2&
Private Const RESOURCE_REMEMBERED As Long = &H3&
Private Const RESOURCEDISPLAYTYPE_DIRECTORY& = &H9
Private Const RESOURCEDISPLAYTYPE_DOMAIN& = &H1
Private Const RESOURCEDISPLAYTYPE_FILE& = &H4
Private Const RESOURCEDISPLAYTYPE_GENERIC& = &H0
Private Const RESOURCEDISPLAYTYPE_GROUP& = &H5
Private Const RESOURCEDISPLAYTYPE_NETWORK& = &H6
Private Const RESOURCEDISPLAYTYPE_ROOT& = &H7
Private Const RESOURCEDISPLAYTYPE_SERVER& = &H2
Private Const RESOURCEDISPLAYTYPE_SHARE& = &H3
Private Const RESOURCEDISPLAYTYPE_SHAREADMIN& = &H8
Private Const RESOURCETYPE_ANY As Long = &H0&
Private Const RESOURCETYPE_DISK As Long = &H1&
Private Const RESOURCETYPE_PRINT As Long = &H2&
Private Const RESOURCETYPE_UNKNOWN As Long = &HFFFF&
Private Const RESOURCEUSAGE_ALL As Long = &H0&
Private Const RESOURCEUSAGE_CONNECTABLE As Long = &H1&
Private Const RESOURCEUSAGE_CONTAINER As Long = &H2&
Private Const RESOURCEUSAGE_RESERVED As Long = &H80000000
Private Const NO_ERROR = 0
Private Const ERROR_MORE_DATA = 234                        'L    //
dderror
Private Const RESOURCE_ENUM_ALL As Long = &HFFFF
Private Type NETRESOURCE
    dwScope As Long
    dwType As Long
    dwDisplayType As Long
    dwUsage As Long
    pLocalName As Long
    pRemoteName As Long
    pComment As Long
    pProvider As Long
End Type
Private Type NETRESOURCE_REAL
    dwScope As Long
    dwType As Long
    dwDisplayType As Long
    dwUsage As Long
    sLocalName As String
    sRemoteName As String
    sComment As String
    sProvider As String
End Type
Private Declare Function WNetAddConnection2 Lib "mpr.dll" Alias
"WNetAddConnection2A" (lpNetResource As NETRESOURCE, ByVal lpPassword As
String, ByVal lpUserName As String, ByVal dwFlags As Long) As Long
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
NETRESOURCE, lpBufferSize As Long) As Long
Private Declare Function WNetCloseEnum Lib "mpr.dll" (ByVal hEnum As
Long) As Long
Private Declare Function VarPtrAny Lib "vb40032.dll" Alias "VarPtr"
(lpObject As Any) As Long
Private Declare Sub CopyMem Lib "kernel32" Alias "RtlMoveMemory" (lpTo
As Any, lpFrom As Any, ByVal lLen As Long)
Private Declare Sub CopyMemByPtr Lib "kernel32" Alias "RtlMoveMemory"
(ByVal lpTo As Long, ByVal lpFrom As Long, ByVal lLen As Long)
Private Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" (ByVal
lpString1 As String, ByVal lpString2 As Any) As Long
Private Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" (ByVal
lpString As Any) As Long
Private Declare Function getusername Lib "advapi32.dll" Alias
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Declare Function GetComputerName Lib "kernel32" Alias
"GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Public strUserName As String
Public strMachinerName As String
Private Declare Function WNetGetUser Lib "mpr" Alias "WNetGetUserA"
(ByVal lpName As String, ByVal lpUserName As String, lpnLength As Long)
As Long
Sub ReadNetUsers()
    Const MAX_RESOURCES = 256
    Const NOT_A_CONTAINER = -1
    Dim bFirstTime As Boolean
    Dim lReturn As Long
    Dim hEnum As Long
    Dim lCount As Long
    Dim lMin As Long
    Dim lLength As Long
    Dim l As Long
    Dim lBufferSize As Long
    Dim lLastIndex As Long
    Dim uNetApi(0 To MAX_RESOURCES) As NETRESOURCE
    Dim uNet() As NETRESOURCE_REAL
    Static rCosa As String, rTipo As String
    Static rNome As String, rNote As String, rUser As String
    Static ret As Long
    rEle1.Clear
    rEle2.Clear
    rEle3.Clear
    bFirstTime = True
    Do
        If bFirstTime Then
            lReturn = WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY,
RESOURCEUSAGE_ALL, ByVal 0&, hEnum)
            bFirstTime = False
        Else
            If uNet(lLastIndex).dwUsage And RESOURCEUSAGE_CONTAINER Then
                lReturn = WNetOpenEnum(RESOURCE_GLOBALNET,
RESOURCETYPE_ANY, RESOURCEUSAGE_ALL, uNet(lLastIndex), hEnum)
            Else
                lReturn = NOT_A_CONTAINER
                hEnum = 0
            End If
            lLastIndex = lLastIndex + 1
        End If
        If lReturn = NO_ERROR Then
            lCount = RESOURCE_ENUM_ALL
            Do
                lBufferSize = UBound(uNetApi) * Len(uNetApi(0)) / 2
                lReturn = WNetEnumResource(hEnum, lCount, uNetApi(0),
lBufferSize)
                If lCount > 0 Then
                    ReDim Preserve uNet(0 To lMin + lCount - 1) As
NETRESOURCE_REAL
                    For l = 0 To lCount - 1
                        'Each Resource will appear here as uNet(i)
                        uNet(lMin + l).dwScope = uNetApi(l).dwScope
                        uNet(lMin + l).dwType = uNetApi(l).dwType
                        uNet(lMin + l).dwDisplayType =
uNetApi(l).dwDisplayType
                        uNet(lMin + l).dwUsage = uNetApi(l).dwUsage
                        If uNetApi(l).pLocalName Then
                            Debug.Print "LOCAL"
                            lLength = lstrlen(uNetApi(l).pLocalName)
                            uNet(lMin + l).sLocalName = Space$(lLength)
                            CopyMem ByVal uNet(lMin + l).sLocalName,
ByVal uNetApi(l).pLocalName, lLength
                        End If
                        If uNetApi(l).pRemoteName Then
                            lLength = lstrlen(uNetApi(l).pRemoteName)
                            uNet(lMin + l).sRemoteName = Space$(lLength)
                            CopyMem ByVal uNet(lMin + l).sRemoteName,
ByVal uNetApi(l).pRemoteName, lLength
                        End If
                        If uNetApi(l).pComment Then
                            lLength = lstrlen(uNetApi(l).pComment)
                            uNet(lMin + l).sComment = Space$(lLength)
                            CopyMem ByVal uNet(lMin + l).sComment, ByVal
uNetApi(l).pComment, lLength
                        End If
                        If uNetApi(l).pProvider Then
                            lLength = lstrlen(uNetApi(l).pProvider)
                            uNet(lMin + l).sProvider = Space$(lLength)
                            CopyMem ByVal uNet(lMin + l).sProvider,
ByVal uNetApi(l).pProvider, lLength
                        End If
                    Next l
                End If
                lMin = lMin + lCount
            Loop While lReturn = ERROR_MORE_DATA
        End If
        If hEnum Then
            l = WNetCloseEnum(hEnum)
        End If
    Loop While lLastIndex < lMin
    If UBound(uNet) > 0 Then
        username
        For l = 0 To UBound(uNet)
            Select Case uNet(l).dwDisplayType
                Case RESOURCEDISPLAYTYPE_DIRECTORY&
                    rCosa = "Directory..."
                Case RESOURCEDISPLAYTYPE_DOMAIN
                    rCosa = "Domain..."
                Case RESOURCEDISPLAYTYPE_FILE
                    rCosa = "File..."
                Case RESOURCEDISPLAYTYPE_GENERIC
                    rCosa = "Generic..."
                Case RESOURCEDISPLAYTYPE_GROUP
                    rCosa = "Group..."
                Case RESOURCEDISPLAYTYPE_NETWORK&
                    rCosa = "Network..."
                Case RESOURCEDISPLAYTYPE_ROOT&
                    rCosa = "Root..."
                Case RESOURCEDISPLAYTYPE_SERVER
                    rCosa = "Server..."
                Case RESOURCEDISPLAYTYPE_SHARE
                    rCosa = "Share..."
                Case RESOURCEDISPLAYTYPE_SHAREADMIN&
                    rCosa = "ShareAdmin..."
                Case Else
                    rCosa = "???..."
            End Select
            Select Case uNet(l).dwType
                Case RESOURCETYPE_ANY
                    rTipo = "Any"
                Case RESOURCETYPE_DISK
                    rTipo = "Disk"
                Case RESOURCETYPE_PRINT
                    rTipo = "Printer"
                Case RESOURCETYPE_UNKNOWN
                    rTipo = "Unknown"
                Case Else
                    rTipo = "???"
            End Select
            rNome = uNet(l).sRemoteName
            'rNote = uNet(l).sComment
            ''If InStr(1, rCosa, "server", 1) > 0 Then
                rEle1.AddItem rCosa
                rEle2.AddItem rTipo
                rEle3.AddItem rNome
            ''End If
        Next l
    End If
End Sub
Private Sub username()
  On Error Resume Next
    'Create a buffer
    strUserName = String(255, Chr$(0))
    'Get the username
    getusername strUserName, 255
    'strip the rest of the buffer
    strUserName = Left$(strUserName, InStr(strUserName, Chr$(0)) - 1)
     'Create a buffer
    strMachinerName = String(255, Chr$(0))
    GetComputerName strMachinerName, 255
    'remove the unnecessary chr$(0)'s
    strMachinerName = Left$(strMachinerName, InStr(1, strMachinerName,
Chr$(0)) - 1)
End Sub
Private Sub Command1_Click()
    ReadNetUsers
End Sub
Private Sub Form_Load()
    OldStatus = -1
End Sub
#####################
-> GbC
http://www.gbcweb.com

Grazie tanto,
i risultati alla fine sono venuti fuori, grazie
