We need you!

We're working hard on the next version of Developer Fusion. Let us know what you think we should be up to!

Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Rated
Read 21,921 times

Related Categories

Get the PC Name

Many API calls such as GetComputerName and GetUserName can be used fairly easily to get common information... once you know how. This example shows you how to get the Computer Name, but could easily be adapted for GetUserName.

Private Declare Function apiGetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Private Function GetPCName() As String
Dim sResult As String
    '// Computer Name
    '// Fill the buffer with the maximum length (255 characters)
    sResult = Space(255)
    '// Call the API function
    Call apiGetComputerName(sResult, 255)
    '// Get the returned value, stripping off any trailing null characters
    '// lPos contains the length of the computer name
    GetPCName =StripTerminator(sResult)
End Sub

Private Function StripTerminator(sString As String) As String
    StripTerminator = Left$(sString, InStr(sString, Chr$(0)) - 1)
End Function

James first started writing tutorials on Visual Basic in 1999 whilst starting this website (then known as VB Web). Since then, the site has grown rapidly, and James has written numerous tutorials, articles and reviews on VB, PHP, ASP and C#. In October 2003, James formed the company Developer Fusion Ltd, which owns this website, and also offers various development services. In his spare time, he's a 3rd year undergraduate studying Computer Science in the UK. He's also a Visual Basic MVP.

Comments

  • Outlook

    Posted by Scott True on 16 Jan 2002

    I need to use this in Outlook on a form so that it will automatically detect the computer name when the form opens. Is there a way to implement this and please explain how. I'm really new at vb.
    Than...