Option Explicit
Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" _
(ByVal Buffer As String, _
Size As Long) As Long
Sub GetMachineName()
Dim strBuf As String * 16, strPcName As String, lngPc As Long
lngPc = GetComputerName(strBuf, Len(strBuf))
If lngPc <> 0 Then
strPcName = Left(strBuf, InStr(strBuf, vbNullChar) - 1)
MsgBox "Your Name of Computer is :" & strPcName
Else
MsgBox "Error"
End If
End Sub
Option Explicit
Declare Function GetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) _
As Long
Sub getUser()
Dim s As String
Dim cnt As Long
Dim dl As Long
Dim CurUser As String
cnt = 199
s = String$(200, 0)
dl = GetUserName(s, cnt)
If dl <> 0 Then CurUser = Left$(s, cnt) Else CurUser = ""
MsgBox CurUser
End Sub
Tried those commands they don't seem to be coming through over the network
What exactly does that mean? What values did you get when you accessed those functions, was it real data but not the computer you expected? Or blank? Or errors?
Are the users running Excel on a local desktop machine, or is this a virtual desktop configuration?
=========================================================
»bp
You can get the computer and user names using Environ.
Open in new window