Imports System.Management
Public Function GetFirstMac() As String
' returns the mac address without :'s for first network adapter found
' returns "" if none found
Const sQuery = "SELECT MacAddress FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = true"
Dim oRet As ManagementObjectSearcher = New ManagementObjectSearcher(sQuery)
Dim MCol As ManagementObjectCollection = oRet.Get()
Dim MObj As ManagementObject
Dim MacNow As String
For Each MObj In MCol
Debug.WriteLine(MObj("MacAddress"))
MacNow = MObj("MacAddress")
If (Not IsNothing(MacNow)) Then
MacNow = Replace(MacNow, ":", "")
If Len(MacNow) = 6 * 2 Then ' 6 x hex
Return MacNow
End If
End If
Next
Return ""
End Function
There's another version at :
http://www.dotnet247.com/247reference/msgs/4/21219.aspx
If you want to know how to do it in a PocketPC, see :
http://www.developmentnow.com/g/18_2...pplication.htm
Google is your friend.
Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ :
http://asp.net.do/faq/
Foros de ASP.NET en EspaƱol :
http://asp.net.do/foros/
======================================
"Maxood" <Ma****@discussions.microsoft.com> wrote in message news:B2**********************************@microsof t.com...
Can you tell me how to read the MAC address of a workstation in VB.Net.Lets
say that i wan to generate a primary key based on MAC addresses.
"Karl Seguin" wrote:
The only way I've ever done this is via the Guid.NewGuid static member...
dim id as Guid = Guid.NewGuid
id.ToString()
http://en.wikipedia.org/wiki/GUID
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"Maxood" <Ma****@discussions.microsoft.com> wrote in message
news:F4**********************************@microsof t.com... >I want to generate a primary key in ASP.Net through VB.Net code.Can someone
> give some tips and ideas how to do that.What i am thinking is to:
>
> 1.Create an array of values(characters) from 0 to 9 and 'A' to 'Z'.
> 2.Then use a nested For loop to create various combinations.
> 3.Then checking whether these combinations exist in the field of the table
> or not.
>
> Can someone suggest a better way of doing that.Is it a good idea to create
> a
> primary key in runtime as above stated.
> What if i have to create a primary key for user ids for users from all
> over
> the world(probably too huge or unlimited)?