Click to See Complete Forum and Search --> : Machine name
death
Dec 1st, 1999, 06:57 PM
How do use an API or other method to find the name of the computer that you are on.
Any help is much appricated
Serge
Dec 1st, 1999, 07:04 PM
You can use GetComputerName API:
Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
'--------Put this on any event
Dim lRet As Long
Dim strComputerName As String
strComputerName = Space(125)
lRet = GetComputerName(strComputerName, Len(strComputerName))
If lRet Then strComputerName = Left(strComputerName, InStr(strComputerName, vbNullChar) - 1)
strComputerName now holds the name of the computer.
------------------
Serge
Software Developer
Serge_Dymkov@vertexinc.com
Access8484@aol.com
ICQ#: 51055819 (http://www.icq.com/51055819)
Ishamel
Dec 1st, 1999, 07:04 PM
I use this Environ() array to return a PC name.
Public Function GetComputerName() As String
'This Function will return the current PC's number
Dim sEnvironmentString As String
Dim Indx As Integer
Indx = 1 ' Initialize index to 1.
Do
sEnvironmentString = Environ(Indx) ' Get environment
If Left(sEnvString, 13) = "COMPUTERNAME=" Then ' Check PATH entry.
GetComputerName = Right(sEnvironmentString, Len(sEnvironmentString) - 13)
Exit Function
Else
Indx = Indx + 1 ' Not COMPUTERNAME entry, so increment
End If
Loop Until sEnvironmentString = ""
GetComputerName = "(Unable to identify PC)"
End Function
Serge
Dec 1st, 1999, 07:55 PM
Yes, you can, but API is much faster and you don't have to use any loops.
------------------
Serge
Software Developer
Serge_Dymkov@vertexinc.com
Access8484@aol.com
ICQ#: 51055819 (http://www.icq.com/51055819)
Ishamel
Dec 1st, 1999, 08:03 PM
Ye - I've already replaced my code with yours. :)
death
Dec 2nd, 1999, 02:25 AM
Thanks to both of you
I used the first piece of code as that seems to be the general consensus of oppinion
thanks again
Death
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.