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
Printable View
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
I got this from API guide...
If this doesn't help, post what you tried here and I will see what I can do.Code: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: [email protected]
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 you are looking for the name of the computer you are using, you can use the API posted above or use the Environ function.
Code:MsgBox Environ ("COMPUTERNAME")
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.
Thank you. That was exactly what i needed. thank u all..!