A] in order to find the MAC Address of your network card...
1.- You need to make a refference to System.Management dll
2.- at the top of you class type
Imports System.Management
Public Class Form1
3-Function
Private Function get_MACAdd() as string
Dim pcMacAddress As String = ""
Dim mc As System.Management.ManagementClass
Dim mo As ManagementObject
mc = New ManagementClass("Win32_NetworkAdapterConfiguration")
Dim moc As ManagementObjectCollection = mc.GetInstances()
For Each mo In moc
If mo.Item("IPEnabled") = True Then
pcMacAddress &= "MAC address " & mo.Item("MacAddress").ToString() & vbCrLf
End If
Next
'// MsgBox(pcMacAddress)
return pcMacAddress
End Function
MAC Address is unique, but if you ever change your network card there another MAC Address
B] Also your PC-Name is unique on the network
dim myPCName as string=getWorkStation().ToLower
Public Function getWorkStation() As String
Dim aStr As String = "none"
Try
Dim RegKey As Microsoft.Win32.RegistryKey
RegKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("HARDWARE\DESCRIPTION\System", False)
aStr = Environment.MachineName
RegKey.Close()
Catch ex As Exception
End Try
Return aStr
End Function
-or- a better way
Dim myPCName As String = System.Environment.MachineName.ToString.ToLower
MsgBox(myPCName)
C] Finally this is a unique id
Dim myUniqeID as string=createUniqueCode(ctype(weekday(today),string))
Public Function createUniqueCode(ByVal aStr As String) As String
Dim c As String = ""
Dim xTimer As String = Microsoft.VisualBasic.DateAndTime.Timer.ToString.Replace(",", "")
Try
Dim mName As String = ""
If System.Environment.MachineName.ToString.Length > 0 Then
If System.Environment.MachineName.ToString.Length < 4 Then
mName = Mid(System.Environment.MachineName.ToString & "abc", 1, 3)
Else
mName = Mid(System.Environment.MachineName.ToString, 1, 3)
End If
Else
If xTimer.Length > 0 Then
If xTimer.Length < 4 Then
mName = Mid(xTimer & "098", 1, 3)
Else
mName = xTimer
End If
Else
mName = "que"
End If
End If
c = Microsoft.VisualBasic.DateAndTime.Year(Today) & Microsoft.VisualBasic.DateAndTime.Month(Today) & Microsoft.VisualBasic.DateAndTime.Day(Today) & "-" & xTimer & mName & aStr
Catch ex As Exception
c = "sfjsdjfsdjasdas4123ortret8mf0984131" & DaysName(Today)
Finally
End Try
Return c
End Function
|