Results 1 to 5 of 5

Thread: How to retrieve the computer name?

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2000
    Location
    Kerala, India
    Posts
    8

    Question

    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

  2. #2
    Lively Member
    Join Date
    Jun 2000
    Posts
    122
    I got this from API guide...

    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 this doesn't help, post what you tried here and I will see what I can do.

  3. #3
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    736
    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")

  4. #4
    Addicted Member KrishnaSantosh's Avatar
    Join Date
    Feb 2001
    Location
    Coimbatore
    Posts
    210
    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.

  5. #5

    Thread Starter
    New Member
    Join Date
    Sep 2000
    Location
    Kerala, India
    Posts
    8

    Thumbs up

    Thank you. That was exactly what i needed. thank u all..!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width