"Jozef" <SP**********@t elus.net> wrote in message
news:ZO%Se.9407 0$Hk.62070@pd7t w1no...
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 GetComputerName A Lib "kernel32" _
(ByVal lpBuffer As String, nSize As Long) As Long
Public Function CurrentMachineN ame() As String
Dim lSize As Long
Dim sBuffer As String
sBuffer = Space$(16)
lSize = Len(sBuffer)
If GetComputerName A(sBuffer, lSize) Then
CurrentMachineN ame = Left$(sBuffer, lSize)
End If
End Function
'---------------------< end code >---------------------
Now you can retrieve the current machine name with CurrentMachineN ame().