VB 2003 -> VB 2005 conversion questions

M

Mika M

Hi!

Earlier using VB 2003 I used...

Net.Dns.Resolve(Net.Dns.GetHostName()).AddressList(0).ToString()

....to retrieve IP-address of the local (first) NIC.

Now I'm starting to use VB 2005, and don't know how to do this same (get
IP-address) using new way of VB 2005?


Other question is how to determine windows version by using VB 2005? I
mean something like...

http://support.microsoft.com/default.aspx?scid=kb;en-us;304289#XSLTH3182121122120121120120

....was for the older VB.
 
J

Joergen Bech

Hi!

Earlier using VB 2003 I used...

Net.Dns.Resolve(Net.Dns.GetHostName()).AddressList(0).ToString()

...to retrieve IP-address of the local (first) NIC.

Now I'm starting to use VB 2005, and don't know how to do this same (get
IP-address) using new way of VB 2005?

It's pretty much the same:


Debug.WriteLine(System.Net.Dns.GetHostEntry(My.Computer.Name).AddressList(0))

Just an example. Don't think you should hardcode the (0) at the end.

Not sure there is a shorter way of writing it.
Other question is how to determine windows version by using VB 2005? I
mean something like...

http://support.microsoft.com/default.aspx?scid=kb;en-us;304289#XSLTH3182121122120121120120

...was for the older VB.

Debug.WriteLine(My.Computer.Info.OSFullName & ": " &
My.Computer.Info.OSPlatform & ": " & My.Computer.Info.OSVersion)

(on my machine, result is "Microsoft Windows XP Professional: Win32NT:
5.1.2600.131072")

/JB
 
K

Ken Tucker [MVP]

Hi,

DNS.Resolve is obsolete use dns.GetHostEntry instead. You can use
environment.machinename instead of dns.gethostname if you would like.

Dim MyIp As Net.IPAddress
MyIp = Net.Dns.GetHostEntry(Net.Dns.GetHostName()).AddressList(0)
Me.Text = MyIp.ToString


Ken
 
M

Mika M

Thanks for your both - Jörgen and Ken - I got it!

Still one more question :) Is there new way for
System.Environment.UserName too? I mean something like My.something...

Anyway System.Environment.UserName is working fine - I'm just curious.
 
J

Joergen Bech

Thanks for your both - Jörgen and Ken - I got it!

Still one more question :) Is there new way for
System.Environment.UserName too? I mean something like My.something...

Anyway System.Environment.UserName is working fine - I'm just curious.

These two lines should produce the same result:

Debug.WriteLine("My User name: " & My.User.Name)

Debug.WriteLine("SysEnv User Name: " &
System.Environment.UserDomainName & "\" & System.Environment.UserName)

/JB
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top