I
I
Ivan2020-02-13 15:09:19
.NET
Ivan, 2020-02-13 15:09:19

Determining the current Windows user from under a service running as another user with minimal privileges?

Good afternoon.
I am writing a service on .Net Core.
It is assumed that the service will be started from a technological account with minimal rights (the maximum allowable minimum).
Task: Determine the active user of the system.
Using WMI, you can get the current user: wmic computersystem get username (SELECT UserName FROM Win32_ComputerSystem) The
trouble is that it is in the case when the service will be started from a technological account with minimal rights SELECT UserName FROM Win32_ComputerSystem returns an empty string. If you run the service as an administrator instead of a technological account, then everything works correctly.
Actually a question: how to receive the current user in my case?
I will listen to all suggestions and I will be very grateful.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex, 2020-02-18
@asilonos

You need to Ask on rsdn.ru - rsdn.org/forum/winapi
The service can receive SERVICE_ACCEPT_SESSIONCHANGE notifications and there you can find out if you are logged in using GetSessionUsername()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question