GetComputerName Function

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

Platforms: Win 95/98, Win NT

GetComputerName reads the name of the user's computer. The name is put into the string variable passed as lpBuffer. The function returns 0 if an error occured or 1 if successful.

lpBuffer
A string large enough to hold the returned computer name terminated by a null character.
nSize
The length in characters of lpBuffer.

Example:

' Display the computer's name
Dim compname As String, retval As Long  ' string to use as buffer & return value

compname = Space(255)  ' set a large enough buffer for the computer name
retval = GetComputerName(compname, 255)  ' get the computer's name
' Remove the trailing null character from the strong
compname = Left(compname, InStr(compname, vbNullChar) - 1)
Debug.Print compname  ' display name

Category: System Information
Back to the index.


Go to Paul Kuliniewicz's Home Page.
E-mail: rogue953@hotmail.com
This page is at http://skyscraper.fortunecity.com/transmission/45/api/g/getcomputername.html