Results 1 to 5 of 5

Thread: Help on retrieving Local Computer Name{RESOLVED]

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2004
    Posts
    86

    Resolved Help on retrieving Local Computer Name{RESOLVED]

    I need a function that can return the name of the local machine.

    Is there such a function already in VB ?

    Like example :

    'it will return the computer id/name which I am running on right now.
    MyCompName = getcompname()

    Please help.

    I need this urgently.


    Many thanks and gratitude !!!
    Last edited by icongroup2003; Jul 26th, 2005 at 08:20 PM.

  2. #2
    Addicted Member Paradox's Avatar
    Join Date
    Sep 2004
    Location
    Nairobi
    Posts
    189

    Re: Help on retrieving Local Computer Name

    Peny wise pound Foolish

  3. #3
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Help on retrieving Local Computer Name

    There is an API function you can use. Here's a wrapper function for that API function.
    VB Code:
    1. Private Declare Function GetComputerName _
    2.  Lib "kernel32.dll" Alias "GetComputerNameA" ( _
    3.  ByVal lpBuffer As String, _
    4.  ByRef nSize As Long) As Long
    5.  
    6. Public Function GetCompName() As String
    7.     Dim sBuff As String
    8.     Dim nLen As Long
    9.     nLen = 215 'probably to large buffer
    10.     sBuff = Space$(nLen + 1)
    11.     If GetComputerName(sBuff, nLen) Then
    12.         GetCompName = Left$(sBuff, nLen)
    13.     Else
    14.         sBuff = Space$(nLen)
    15.         Call GetComputerName(sBuff, nLen)
    16.         GetCompName = Left$(sBuff, nLen)
    17.     End If
    18. End Function

  4. #4
    New Member
    Join Date
    Jul 2005
    Location
    Texas
    Posts
    2

    Re: Help on retrieving Local Computer Name

    Declare Function GetUserNameA Lib "advapi32.dll" (ByVal lpBuffer As String, nSize As Long) As Long
    Declare Function GetComputerNameA Lib "kernel32" (ByVal lpBuffer As String, nSize As Long) As Long

    Public Function GetUserName() As String
    Dim UserName As String * 255
    Call GetUserNameA(UserName, 255)
    GetUserName = Left$(UserName, InStr(UserName, Chr$(0)) - 1)
    End Function


    Public Function GetComputerName() As String
    Dim UserName As String * 255

    Call GetComputerNameA(UserName, 255)
    GetComputerName = Left$(UserName, InStr(UserName, Chr$(0)) - 1)
    End Function

    'Put in module
    'Call this like
    'Text1.text = "Hello " & GetUserName & " On " & GetComputerName

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Sep 2004
    Posts
    86

    Re: Help on retrieving Local Computer Name{RESOLVED]

    Thanks for the help. It solved my simple problem.

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