Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can you obtain the Machine Id using VB? 1

Status
Not open for further replies.

LordPonsonby

Programmer
Dec 14, 2000
1
0
0
AU
Does anyone know how to obtain the machine id using Visual Basic?
 
Hope this is what you are looking for.
It returns the network user name


Public Function CStringToVBString(psCString As String) As String
' **********
' Purpose: Convert a C string to a VB string
' Parameters: (Input Only)
' psCString - the C string to convert
' Returns: The converted VB string
' Notes:
' Returns everything to the left of the first Null character
' **********

Dim sReturn As String
Dim iNullCharPos As Integer

iNullCharPos = InStr(psCString, vbNullChar)

If iNullCharPos > 0 Then
' return everything left of the null
sReturn = Left(psCString, iNullCharPos - 1)
Else
' no null, return the original string
sReturn = psCString
End If

CStringToVBString = sReturn

End Function

Finally, here's the wrapper around Win32's WNetGetUser function:
Public Function WNetGetUser() As String
' **********
' Purpose: Retrieve the network user name
' Paramters: None
' Returns: The indicated name
' Notes:
' A zero-length string is returned if the function fails
' **********

Dim lpUserName As String
Dim lpnLength As Long
Dim lResult As Long

lpnLength = 256
lpUserName = Space(lpnLength)

lResult = w32_WNetGetUser(vbNullString, lpUserName, lpnLength)

If lResult = NO_ERROR Then
WNetGetUser = CStringToVBString(lpUserName)
Else
WNetGetUser = ""
End If

End Function

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top