excelvbams-accesswindows-7remote-desktop

Get Current user's Workstation name logged into Host computer


I have a host machine running windows-7 and users from the home network login using windows remote desktop connection and run some applications , I can visually see the log of who logged in under

Event Viewer->Windows Logs->Security->Audit Success->Details->Workstation name

Since only one connection is allowed using Remote Desktop connection, I want to display in an access database who the current user is, from the audit trail so users know if anyone is currently using the Host machine

So basically a VBA code to grab the most recent workstation that logged in, specially I am interested in Event ID-4624

I am open for other suggestions!

what I have tried so far?

Function Reachable(strComputer) As String  'Test Connectivty to computer
'On Error Resume Next
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = objSWbemLocator.ConnectServer(strComputer, "root\cimv2", "username", "password")

Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_NetworkLoginProfile")

For Each objItem In colItems
    Reachable = "Full Name: " & objItem.FullName

Next
End Function

Solution

  • Would this work?

    Dim sHostName As String
    
    sHostName = Environ$("computername")