Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB Visual-Studio
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 28-Jan-11 5:16am
tupacIT188
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
tupacIT at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You can try it with these shell commands:
 
netsh interface set interface "Network Adapter name" DISABLED
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.
  Permalink  
v2
Comments
tupacIT at 28-Jan-11 11:07am
   
John, Thanks I attempted that but it does not work for my LAN in Windows xp on wireless NIC.
John Simmons / outlaw programmer at 28-Jan-11 11:24am
   
I recommend that you search google, then.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

I finally figured out and the code is below"
'' 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
  Permalink  
v2

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

  Print Answers RSS
0 OriginalGriff 5,170
1 DamithSL 4,357
2 Maciej Los 3,750
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,851


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 15 Mar 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100