Set shellApp = CreateObject("shell.application") Set oControlPanel = shellApp.Namespace(ssfCONTROLS)
Set oNetConnections = Nothing For Each folderitem In oControlPanel.items If folderitem.Name = "网络和拨号连接" Then ' If folderitem.Name = "Network Connections" Then '英文 Set oNetConnections = folderitem.getfolder: Exit For End If Next
If oNetConnections Is Nothing Then MsgBox "Couldn't find 'Network Connections' folder" Exit Sub End If
Set oLanConnection = Nothing For Each folderitem In oNetConnections.items If LCase(folderitem.Name) = LCase(sConnectionName) Then Set oLanConnection = folderitem: Exit For End If Next
If oLanConnection Is Nothing Then MsgBox "Couldn't find '" & sConnectionName & "' item" Exit Sub End If
bEnabled = True Set oEnableVerb = Nothing Set oDisableVerb = Nothing For Each Verb In oLanConnection.verbs Debug.Print Verb.Name If Verb.Name = sEnableVerb Then Set oEnableVerb = Verb bEnabled = False Exit For End If If Verb.Name = sDisableVerb Then Set oDisableVerb = Verb Exit For End If Next
If bEnabled Then oDisableVerb.DoIt Else oEnableVerb.DoIt End IfEnd Sub Private Sub Command1_Click() ToggleLanConnection End Sub看到的,对不同的系统,某些地方,比如网络连接的名称要做一定的修改
'中文2000下通过 Private Sub ToggleLanConnection()
Const ssfCONTROLS = 3
sConnectionName = "本地连接"
' sConnectionName = "Local Area Connection" '英文
sEnableVerb = "启用(&A)"
sDisableVerb = "禁用(&B)"
' sEnableVerb = "En&able" '英文
' sDisableVerb = "Disa&ble" '英文
Set shellApp = CreateObject("shell.application")
Set oControlPanel = shellApp.Namespace(ssfCONTROLS)
Set oNetConnections = Nothing
For Each folderitem In oControlPanel.items
If folderitem.Name = "网络和拨号连接" Then
' If folderitem.Name = "Network Connections" Then '英文
Set oNetConnections = folderitem.getfolder: Exit For
End If
Next
If oNetConnections Is Nothing Then
MsgBox "Couldn't find 'Network Connections' folder"
Exit Sub
End If
Set oLanConnection = Nothing
For Each folderitem In oNetConnections.items
If LCase(folderitem.Name) = LCase(sConnectionName) Then
Set oLanConnection = folderitem: Exit For
End If
Next
If oLanConnection Is Nothing Then
MsgBox "Couldn't find '" & sConnectionName & "' item"
Exit Sub
End If
bEnabled = True
Set oEnableVerb = Nothing
Set oDisableVerb = Nothing
For Each Verb In oLanConnection.verbs
Debug.Print Verb.Name
If Verb.Name = sEnableVerb Then
Set oEnableVerb = Verb
bEnabled = False
Exit For
End If
If Verb.Name = sDisableVerb Then
Set oDisableVerb = Verb
Exit For
End If
Next
If bEnabled Then
oDisableVerb.DoIt
Else
oEnableVerb.DoIt
End IfEnd Sub
Private Sub Command1_Click()
ToggleLanConnection
End Sub看到的,对不同的系统,某些地方,比如网络连接的名称要做一定的修改