Results 1 to 5 of 5

Thread: Help on retrieving Local Computer Name{RESOLVED]

Hybrid View

  1. #1
    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

  2. #2
    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

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