Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a basic form to enable or disable a network adapter in windows xp when an user select the enable or disable button from a form. I need help writing the basic code to get start any suggestions or link will be appreciated.
Posted

I finally figured out and the code is below"
VB
'' Const ssfCONTROLS = 3
        'Dim ssfCONTROLS
        'ssfCONTROLS = 3
        'Dim vmNic1 = "VMnet1"
        'Dim vmNic2 = "VMnet8"

        'Dim sDisableVerb As String = "Disable"
        'Dim sEnableVerb As String = "Enable"


        'Dim ShellApp As New Shell32.Shell()
        'Dim oControlPanel As Shell32.Folder = ShellApp.NameSpace(ssfCONTROLS)
        'Dim folderitem As Shell32.FolderItem
        'Dim oNetConnections As Shell32.Folder = Nothing
        'Dim oLanConnection As Shell32.FolderItem = Nothing
        ''Dim Verb As String = Nothing


        ''oNetConnections = Nothing
        'For Each folderitem In oControlPanel.Items()
        '    Debug.WriteLine("Loop 1: " & folderitem.Name)
        '    If folderitem.Name = "Network Connections" Then
        '        Debug.WriteLine("Loop 2: " & folderitem.Name)
        '        oNetConnections = folderitem.GetFolder
        '        Exit For
        '    End If
        'Next
        'For Each folderitem In oNetConnections.Items
        '    If folderitem.Name.Contains(vmNic1) Then
        '        Debug.WriteLine("Loop 3: " & folderitem.Name)
        '        oLanConnection = folderitem
        '    End If

        'Next
        'For Each Verb As Shell32.FolderItemVerb In oLanConnection.Verbs
        '    If Verb.Name = "En&able" Then
        '        Verb.DoIt()
        '        Exit For
        '    End If
        'Next
        'For Each folderitem In oNetConnections.Items
        '    If folderitem.Name.Contains(vmNic2) Then
        '        Debug.WriteLine("Loop 3: " & folderitem.Name)
        '        oLanConnection = folderitem
        '    End If
        'Next
        'For Each Verb As Shell32.FolderItemVerb In oLanConnection.Verbs
        '    If Verb.Name = "En&able" Then
        '        Verb.DoIt()
        '        Exit For
        '    End If
 
Share this answer
 
v2
You can try it with these shell commands:

netsh interface set interface "Network Adapter name" DISABLED <br />
netsh interface set interface "Network Adapter name" ENABLED 


Of course, I can't guarantee it will work.

Here's a link describing different tings you can do through WMI:

http://msdn.microsoft.com/en-us/library/Aa394595[^]

Keep in mind that it's up to the driver software for the NIC to provide the Enable and Disable methods for the Win32_NetworkAdapter class, and 99 times out of 100, the driver does NOT provide these methods.
 
Share this answer
 
v2
Comments
tupacIT 28-Jan-11 11:07am    
John, Thanks I attempted that but it does not work for my LAN in Windows xp on wireless NIC.
#realJSOP 28-Jan-11 11:24am    
I recommend that you search google, then.
You can not do this using C#.NET or VB.NET.
You will have to use WMI (Windows Management Instrumentation) for this.

Refer http://msdn.microsoft.com/en-us/library/Aa394595[^]

It gives in depth information on enabling disabling the network adapter.
All the best.
 
Share this answer
 
Comments
tupacIT 28-Jan-11 11:07am    
Thanks this was a big help but only releases my dhcp I need a method in WMI to actually disable the NIC adapter.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900