arlanne2 Posted September 29, 2011 Share Posted September 29, 2011 Its has some bugs , but i cant fix the bugs any one can fix this for me? TIAImports Microsoft.Win32Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim networkcard As RegistryKey = Registry.LocalMachine.OpenSubKey("SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}") Try 'Get all the network cards names and add it to Combo Box For Each netcard In networkcard.GetSubKeyNames Dim networkcard2 As RegistryKey = Registry.LocalMachine.OpenSubKey("SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\" & netcard, False, Security.AccessControl.RegistryRights.ReadKey) Dim networkcardname As String = networkcard2.GetValue("DriverDesc") ComboBox2.Items.Add(netcard) ComboBox1.Items.Add(networkcardname) networkcard2.Close() Next networkcard.Close() ComboBox1.SelectedIndex = 0 Catch ex As Exception networkcard.Close() ComboBox1.SelectedIndex = 0 End Try End Sub Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged 'Get the MAC Address of the selected network card Dim netcardnumber As String = ComboBox2.Items.Item(ComboBox1.SelectedIndex) Dim getmac As RegistryKey = Registry.LocalMachine.OpenSubKey("SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\" & netcardnumber, False, Security.AccessControl.RegistryRights.ReadKey) Dim mac As String = getmac.GetValue("NetworkAddress") TextBox1.Text = mac getmac.Close() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Try Dim netcardnumber As String = ComboBox2.Items.Item(ComboBox1.SelectedIndex) 'Using integer in the above will not work Dim chmac As RegistryKey = Registry.LocalMachine.OpenSubKey("SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\" & netcardnumber, True) Dim textmac As String = TextBox1.Text If textmac.Contains("-") Then textmac.Replace("-", "") End If chmac.SetValue("NetworkAddress", textmac) chmac.Close() 'Shell("Command.com /c IPConfig/all") MsgBox("MAC Address changed successfully" & vbNewLine & vbNewLine & "To effect changing MAC Address you need to Disable and Renable the Network card you selected", MsgBoxStyle.Information) Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Critical) End Try End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Try Dim netcardnumber As String = ComboBox2.Items.Item(ComboBox1.SelectedIndex) My.Computer.Registry.LocalMachine.OpenSubKey("SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\" & netcardnumber, True).DeleteValue("NetworkAddress") 'Shell("Command.com /c IPConfig/all") MsgBox("MAC Address succesfully resetted" & vbNewLine & vbNewLine & "To effect changing MAC Address you need to Disable and Renable the Network card you selected", MsgBoxStyle.Information) Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Critical) End Try End SubEnd Class Link to comment Share on other sites More sharing options...
jaclaz Posted September 29, 2011 Share Posted September 29, 2011 Maybe if you post which kind of error(s) you have, that could help. Also, does something "pre-made" work?LIke:http://www.codeproject.com/KB/applications/MacIdChanger.aspxor one of these?:http://lantoolbox.com/articles/find-and-change-spoof-your-mac-address-in-windows-xp/Also, the interrnet is full of examples of similar code, among others:http://forum.codecall.net/visual-basic-programming/10444-see-change-your-mac-address-visual-basic-net.htmljaclaz Link to comment Share on other sites More sharing options...
arlanne2 Posted September 29, 2011 Author Share Posted September 29, 2011 thanks jaclas. here is the errorln31 col13 ch13InvalidArgument=Value of '0' is not valid for 'SelectedIndex'.Parameter name: SelectedIndex Link to comment Share on other sites More sharing options...
gunsmokingman Posted September 29, 2011 Share Posted September 29, 2011 Here is a Vb.Net 2008 app that list all Network AdaptorsAnd there Mac Address.CodePublic Class Form1 Dim Wmi = GetObject("winmgmts:\\.\root\CIMV2") ''' <summary> ''' Load Network Adaptor Info ''' </summary> Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim Col = Wmi.ExecQuery("SELECT * FROM Win32_NetworkAdapter") For Each Obj In Col Try If Obj.AdapterTypeId = 0 Then ComboBox1.Items.Add(Obj.Name) End If Catch ex As Exception End Try Next End Sub ''' <summary> ''' Combobox1 Selection Made ''' </summary> Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged Dim Col = Wmi.ExecQuery("SELECT * FROM Win32_NetworkAdapter") If ListBox1.Items.Count = 1 Then ListBox1.Items.Clear() End If For Each Obj In Col Try If Obj.AdapterTypeId = 0 And Obj.Name = ComboBox1.SelectedItem Then ListBox1.Items.Add(Obj.MACAddress) End If Catch ex As Exception End Try Next End SubEnd ClassSource Code ZipDemo_WmiNetwork.zip Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now