How to check currently logged in users in windows 7

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
rzsedv
Posts: 1
Joined: Fri Jul 08, 2016 6:57 am

How to check currently logged in users in windows 7

Post by rzsedv »

Hi community,

please let me know how to Display the current logged in user from a windows 7 Workstation.
I´ve tryed the scripts\check_users.exe and *.ps1 but it works only on Server 2008 R2 and higher.

I got the result as follow

Server 2008 R2= OK: Domain\User is currently loggen in
Windows 7 = OK: \ is currently loggen in

The Background:
I've 10 rooms with doctors and I need to know which doctor is logged on to the Workstation.
The result will be displeyed in Nagvis to identify for the secretary.

Sincerely,
Alex
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: How to check currently logged in users in windows 7

Post by mcapra »

The following powershell script (I named it check_users.ps1) worked against my Windows 7 machine:

Code: Select all

$computername = 'localhost'

$user = Get-WMIObject Win32_Process -filter 'name="explorer.exe"' -computername $ComputerName |
	ForEach-Object { $owner = $_.GetOwner(); '{0}\{1}' -f $owner.Domain, $owner.User } |
	Sort-Object | Get-Unique
	
if(!$user) {Write-Host ""}
else {Write-Host $user}
My NSClient++ (0.4.x) command configuration:

Code: Select all

[/settings/external scripts/scripts]
check_users = cmd /c echo scripts\check_users.ps1; exit($lastexitcode) | powershell.exe -command -
Testing it from the Nagios XI server:

Code: Select all

[root@localhost libexec]# ./check_nrpe -H 192.168.4.240 -c check_users
Aaron-PC\Aaron
No users logged in:

Code: Select all

[root@localhost libexec]# ./check_nrpe -H 192.168.4.240 -c check_users


Former Nagios employee
https://www.mcapra.com/
Locked