Calling the local PC's property on to VB.NET form

sunnyjulka

Member
Joined
Sep 12, 2005
Messages
17
Programming Experience
1-3
Hi everyone
I don't know if this is possible but I want to get the PC's name into .net Form. If you right click My Computer Icon and choose properties, you can get to computer's name. So, is it possible to do something like that.
Thanks in advance for looking.
 

vis781

Well-known member
Joined
Aug 30, 2005
Messages
2,015
Location
Cambridge, UK
Programming Experience
5-10
Hi, yes this id definately possible, but it depends on what version of vb.net you are running. If it's version 2.0 then it's actually very easy, you can access all of the info that you want in the 'MY' namespace.
However if not then it's a little more complicated abd involves some old fashioned API calls. It'll take a while for me to figure this one out, cos i'm at work. But i'll see what i can do and get back to you.
In the mean time the API call you will need goes something like this....

[Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long]



 

sunnyjulka

Member
Joined
Sep 12, 2005
Messages
17
Programming Experience
1-3
Hey
Thanks for repling. You gave me the idea and someone at work further researched on it and found the following code:

Dim wi As WindowsIdentity
wi = WindowsIdentity.GetCurrent()
MessageBox.Show(wi.Name)

with this code import the following namespace
Imports System.Security.Principal
and this gives us the name of that computer.

thanks
 
Top Bottom