"Jozef" <SP**********@telus.net> wrote in message
news:ZO%Se.94070$Hk.62070@pd7tw1no...
Hello,
Is there a way to find the current machine name using VB? I'm trying to
log user activity, but I'd also like to log the location as well i.e. if
errors occur, then I can get an idea what machine the user was on when the
exception was thrown in case that has anything to do with the issue.
Any help would be great! Thanks!
Paste the following code into a new module:
'--------------------< begin code >--------------------
Private Declare Function GetComputerNameA Lib "kernel32" _
(ByVal lpBuffer As String, nSize As Long) As Long
Public Function CurrentMachineName() As String
Dim lSize As Long
Dim sBuffer As String
sBuffer = Space$(16)
lSize = Len(sBuffer)
If GetComputerNameA(sBuffer, lSize) Then
CurrentMachineName = Left$(sBuffer, lSize)
End If
End Function
'---------------------< end code >---------------------
Now you can retrieve the current machine name with CurrentMachineName().