Does anyone know how to get the computer name off the current machine? I will need to be able to do this on Win 98, 2000, and XP if the method is different for each one.
Printable View
Does anyone know how to get the computer name off the current machine? I will need to be able to do this on Win 98, 2000, and XP if the method is different for each one.
Via the AllApi.Net guide
says it works on 95 and up
VB Code:
'example by Donavon Kuhn ([email protected]) Private Const MAX_COMPUTERNAME_LENGTH As Long = 31 Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long Private Sub Form_Load() Dim dwLen As Long Dim strString As String 'Create a buffer dwLen = MAX_COMPUTERNAME_LENGTH + 1 strString = String(dwLen, "X") 'Get the computer name GetComputerName strString, dwLen 'get only the actual data strString = Left(strString, dwLen) 'Show the computer name MsgBox strString End Sub
Ther codebank forum has a good example of this. Try a search there - this post has been answered 60+ times in the past year.
Yea I tried doing a search for Computer Name, but then I get every post that has computer in it. Do you know how many posts that is? :)
Thanks kleinma. I should of checked the API guide myself hehe, but my first instincts is to always go here. :D