How do use an API or other method to find the name of the computer that you are on.
Any help is much appricated
Printable View
How do use an API or other method to find the name of the computer that you are on.
Any help is much appricated
You can use GetComputerName API:
strComputerName now holds the name of the computer.Code: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)
------------------
Serge
Software Developer
[email protected]
[email protected]
ICQ#: 51055819
I use this Environ() array to return a PC name.
Code:
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
Yes, you can, but API is much faster and you don't have to use any loops.
------------------
Serge
Software Developer
[email protected]
[email protected]
ICQ#: 51055819
Ye - I've already replaced my code with yours. :)
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