哈尔滨哪家眉毛弄得好:如何用VB禁止程序访问网络

来源:百度文库 编辑:中科新闻网 时间:2024/04/28 11:55:45
如何使用Visual Basic禁止程序访问网络,就像防火墙那样,麻烦给出代码或相关API函数及使用方法谢谢!
感谢:_zhidao_但您的答案为VBS语言,且为禁止网络连接!与问题不符

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 If End Sub Private Sub Command1_Click() ToggleLanConnection End Sub
可以用winapi函数中的注册表操作函数,将相应的项删了或禁止就可以了吧