Non sono certo che tu stia scegliendo la strada giusta disabilitando la rete ... comunque eccoti il codice che ho scritto un paio di anni fa ... Controlla se funziona (!), elimina i MsgBox se non ti servono e, soprattutto, adattalo alla lingua inglese dove serve se lo usi con W2K3 ...
codice:Option Explicit Private Const sNetConn = "Rete e connessioni remote" Private Const sConnName = "Connessione alla rete locale (LAN)" Private Sub Command1_Click() DoNetVerb "&Abilita" End Sub Private Sub Command2_Click() DoNetVerb "&Disabilita" End Sub Private Sub DoNetVerb(ByVal NetVerb As String) Dim oShellApp As Object Dim oCtrlPanel As Object Dim oNetConnections As Object Dim oFolder As Object Dim oLanConnection As Object Dim oNetVerb As Object Dim oVerb As Object Dim Wait As Boolean Set oShellApp = CreateObject("Shell.Application") Set oCtrlPanel = oShellApp.Namespace(3) Set oNetConnections = Nothing For Each oFolder In oCtrlPanel.items If LCase(oFolder.Name) = LCase(sNetConn) Then Set oNetConnections = oFolder.GetFolder Exit For End If Next If oNetConnections Is Nothing Then MsgBox "Il folder '" & sNetConn & "' non e' stato trovato.", vbCritical, "Attenzione" Else Set oLanConnection = Nothing For Each oFolder In oNetConnections.items If LCase(oFolder.Name) = LCase(sConnName) Then Set oLanConnection = oFolder Exit For End If Next If oLanConnection Is Nothing Then MsgBox "La connessione '" & sConnName & "' non e' stata trovata.", vbCritical, "Attenzione" Else Set oNetVerb = Nothing For Each oVerb In oLanConnection.verbs If oVerb.Name = NetVerb Then Set oNetVerb = oVerb Exit For End If Next If oNetVerb Is Nothing Then MsgBox "Impossibile eseguire il verbo '" & NetVerb & "'", vbCritical, "Attenzione" Else oNetVerb.DoIt Do Wait = False DoEvents For Each oVerb In oLanConnection.verbs If oVerb.Name = NetVerb Then Wait = True Exit For End If Next Loop While Wait MsgBox "Operazione eseguita." End If End If End If Set oVerb = Nothing Set oNetVerb = Nothing Set oLanConnection = Nothing Set oFolder = Nothing Set oNetConnections = Nothing Set oCtrlPanel = Nothing Set oShellApp = Nothing End Sub

Rispondi quotando