Qualcosa del genere
codice:
Option Explicit
Private Const sNetConn = "Connessioni di rete"
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
For Each oFolder In oNetConnections.items
MsgBox oFolder.Name
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