Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get PC name from Windows 2000

How To

Get PC name from Windows 2000

by  randysmid  Posted    (Edited  )
Create a new module, and save it as "modGetPCName". Paste the following code into the new module:

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

Function fMachineName() As String
Dim lLength As Long, lngX As Long
Dim strPCName As String
lLength = 16
strPCName = String$(lLength, 0)
lvalue = fPCName(strPCName, lLength)
If lvalue <> 0 Then
fMachineName = Left$(strPCName, lLength)
Else
fMachineName = "<< No Name Found !!! >>"
End If
End Function


To use this function, you simply call it from just about anywhere within your application. Here is an example of the usage:
Dim strPCName as String
strPCName = fMachineName
MsgBox "Your pc is named " & strPCName


Questions? rsmith@cta.org
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top