vb.net - An unhandled exception of type 'System.Net.Sockets.SocketException' LAN network -
i made treeview show users on lan network , work.
- when click on user show ip , pcname without problem, but
- when click on main network "homegroup" message below
an unhandled exception of type 'system.net.sockets.socketexception' occurred in system.dll
and highlight line:
with system.net.dns.gethostbyname(compname)
function getipaddress(byval compname string) string dim oaddr system.net.ipaddress dim saddr string try system.net.dns.gethostbyname(compname) oaddr = new system.net.ipaddress(.addresslist(0).address) saddr = oaddr.tostring end getipaddress = saddr end try end function
update
function getipaddress(byval compname string) string dim oaddr system.net.ipaddress dim saddr string try catch ex exception system.net.dns.gethostbyname(compname) end oaddr = new system.net.ipaddress(.addresslist(0).address) saddr = oaddr.tostring end getipaddress = saddr end try end function
here example in vb.net forms application.
i have added comments in code if have more questions, feel free ask:
public class form4 private sub form4_load(sender object, e eventargs) handles mybase.load 'an array of predefined users, testing purposes. 'you can use lan users instead. dim usr_array() string = {"user1", "user2", "user3"} 'first add homegroup node, can add yours. dim mainnode new treenode() 'name of node hold node type, group in case mainnode.name = "group" mainnode.text = "homegroup" me.treeview1.nodes.add(mainnode) 'loop through user list , add them each usr in usr_array dim usrnode new treenode() 'the name of nodes user represent 'the type of nodes usrnode.name = "user" usrnode.text = usr mainnode.nodes.add(usrnode) next usr end sub private sub treeview1_afterselect(sender object, e treevieweventargs) handles treeview1.afterselect 'after select, check if performed mouse click if e.action = treeviewaction.bymouse select case e.node.name case "group" msgbox("group node clicked") case "user" msgbox("user node clicked") 'call getipaddress function here end select end if end sub end class
Comments
Post a Comment