Thursday, February 7, 2019

windows - Create popup asking for login reason


Currently when a user logs in, it sends an email to me and I have to ask why that user logged in. As you can already see the user sometimes feels the need not to reply. This is a requirement for the company I work for, so please do not suggest doing something else in its place.


I have an idea of creating a popup that appears when they login that asks them why they are logging in and then just creates a log file for me to check later. How can I do this on Windows Server 2008 R2 or Windows Server 2012 R2?


Answer



There's nothing built into Windows that will do this. You'll need to write a script or application and fire it off upon logon (say, via the Task Manager).


Here's a basic PowerShell script that can get you going:


# Ask for user reason.
$reason = Read-Host -Prompt 'Why are you logging on?'
# Write reason to Event Log
Write-EventLog -LogName Application -Source WSH -EventID 666 -EntryType Information -Message "User provided reason '$reason' for logon."
# If reason is less than 10 characters, consider it unacceptable, and log the user off.
if ($reason.length -lt 10) {
Write-Host "Reason not good enough (or blank)!"
logoff.exe
}

No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...