• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 162
  • Last Modified:

local machine computer name

This should be fairly simple, at least I think and I'm having a brain fade right now...but can anyone tell me how to get the computername usiong VB of the local machine I'm running the application on?  Not a network UNC...I know how to do that but when I enumerate the drives on my machine and get the UNC's for the mapped drives that works fine but when it hits a local fixed disk I can't get the UNC of the local machine.  

Can anybody help with this?

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

Private Sub Command1_Click()
    Dim sName As String
    Dim lSize As Long
    sName = String(255, Chr(0))
    lSize = 255
    Call GetComputerName(sName, lSize)
    sName = Left(sName, lSize)
    Debug.Print sName
End Sub
davismAuthor Commented:
I should've known that.  Brain fade on my part.  But Thanks!  Greatly appreciated.
Thanks for the code!

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now