Page 1 of 1

How to check currently logged in users in windows 7

Posted: Thu Aug 04, 2016 9:07 am
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

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

Posted: Thu Aug 04, 2016 11:26 am
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