Could someone help me convert this to VB6 please? I have tried to do it my self but I keep coming unstuck with the shell32 definitions. I have posted the original code just so none of my changes cause confusion and it would be nice if a fresh (and more experienced) pair of eyes could have a look at this.
Code:' Switch Boolean (Scope: form or module level) Dim LANEnable As Boolean = True ' ***** Either placed within a button or routine ***** ' Control Panel Identifier Const ssfCONTROLS = 3 ' Enter the name of the connection to manipulate Dim ConnectionName As String = "Local Area Connection" Dim EnableVerb As String = "En&able" Dim DisableVerb As String = "Disa&ble" ' Generate Shell item Dim ShellApp As New Shell32.Shell() ' Obtain the CP Dim ControlPanel As Shell32.Folder = ShellApp.NameSpace(ssfCONTROLS) Dim FolderItem As Shell32.FolderItem Dim NetworkFolder As Shell32.Folder Dim LANConnection As Shell32.FolderItem ' Loop through the items in the control panel and obtain the Network Connections folder For Each FolderItem In ControlPanel.Items() Debug.WriteLine("Loop 1: " & FolderItem.Name) If FolderItem.Name = "Network Connections" Then ' When found - exit the loop NetworkFolder = FolderItem.GetFolder Exit For End If Next ' Debug check If NetworkFolder Is Nothing Then MessageBox.Show("Error - No network folder found") Exit Sub End If ' Obtain the appropriate connection record For Each FolderItem In NetworkFolder.Items() Debug.WriteLine("Loop 2: " & FolderItem.Name) If FolderItem.Name = ConnectionName Then ' When found - exit the loop LANConnection = FolderItem Exit For End If Next ' Debug check If LANConnection Is Nothing Then MessageBox.Show("Error - No LAN entry was not found") Exit Sub End If ' Swtich the LAN toggle LANEnable = Not LANEnable Dim EnableVerbItem, DisableVerbItem, Verb As Shell32.FolderItemVerb ' Run through all available options and obtain the appropriate action For Each Verb In LANConnection.Verbs Debug.WriteLine("Loop 3: " & Verb.Name) If Verb.Name = EnableVerb Then EnableVerbItem = Verb End If If Verb.Name = DisableVerb Then DisableVerbItem = Verb End If Next ' Perform the enable / disable If LANEnable Then EnableVerbItem.DoIt() Else DisableVerbItem.DoIt() End If




Reply With Quote