|
-
Dec 1st, 1999, 07:57 PM
#1
Thread Starter
Lively Member
How do use an API or other method to find the name of the computer that you are on.
Any help is much appricated
-
Dec 1st, 1999, 08:04 PM
#2
You can use GetComputerName API:
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)
strComputerName now holds the name of the computer.
------------------
Serge
Software Developer
[email protected]
[email protected]
ICQ#: 51055819
-
Dec 1st, 1999, 08:04 PM
#3
Lively Member
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
-
Dec 1st, 1999, 08:55 PM
#4
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
-
Dec 1st, 1999, 09:03 PM
#5
-
Dec 2nd, 1999, 03:25 AM
#6
Thread Starter
Lively Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|