PDA

Click to See Complete Forum and Search --> : How to retrieve the computer name?


haisanthosh
Feb 12th, 2001, 08:56 PM
Hi Guys,

How can I get the name of the logged in computer?
I tried the GetComputerName API but it is not returning anything.. Pl. Help.

Thank You

Cybrg641
Feb 12th, 2001, 09:16 PM
I got this from API guide...


Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Sub Form_Load()
'KPD-Team 1998
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
Dim strString As String
'Create a buffer
strString = String(255, Chr$(0))
'Get the computer name
GetComputerName strString, 255
'remove the unnecessary chr$(0)'s
strString = Left$(strString, InStr(1, strString, Chr$(0)))
'Show the computer name
MsgBox strString
End Sub


If this doesn't help, post what you tried here and I will see what I can do.

jbart
Feb 13th, 2001, 07:25 AM
If you are looking for the name of the computer you are using, you can use the API posted above or use the Environ function.

MsgBox Environ ("COMPUTERNAME")

KrishnaSantosh
Feb 13th, 2001, 10:42 AM
private declare function GetComputerName _
Lib Kernel32" Alias "GetComputerNameA" _
(Byval lpBuffer As String,Byval nSize As Long) _
As Long

public function sGetCmpName()

Dim computer as String
Dim bufsize AS Long
Dim RetCode As Long
Dim NullCharPos As Long

Computer=Space(80)
BufSize=Len(Computer)

Retcode=GetComputerName(Computer,Bufsize)

NullCharPos=Instr(Computer,Chr(0))

If NullCharPos>0 then
Computer=Left(Computer,NullCharPos-1)
Else
Computer=""
Endif

End Function

For More Details And API EMail Me.

haisanthosh
Feb 15th, 2001, 09:12 PM
Thank you. That was exactly what i needed. thank u all..!