How to get the Logged-On User

Topics: Archive - General
Mar 27, 2014 at 11:31 AM
Dear all,

I have to write configuration entries into the registry, but no as Service-Account or user which have run the script.

Do we have a possibility to get the Logged-On User which isn't the current script-owner?

I think the installer could only run when a user is logged on or could we read out the Machine-Owner? (I think this isn't possible).

Mar 27, 2014 at 4:13 PM

You can find the current logged in user by a wmi get

$checkuser = Get-WmiObject -Class Win32_ComputerSystem | Select-Object username

$checkuser.username will now contain the current logged on user. I don't think that it grabs the current context, but the actual locally logged in user.