I would like to check programmatically what is the effective user who owns the process, from inside that process, under windows.
Might be winapi, but a .net solution is preferable.
There is an complicated system of which I do not have a perfect control, an .net app gets 'access denied' to some network filesystem path, and hence I would like to know which user should get the privileges to access this path, so I need a user that owns the process which tries to access it.
Asked
Active
Viewed 288 times
1

Davide Piras
- 43,984
- 10
- 98
- 147

Cyryl Płotnicki
- 473
- 6
- 12
-
are you starting the process yourself or is this a win app or web app? why can't you check Environment.Username ? – Davide Piras Oct 26 '11 at 14:16
-
1possible duplicate of [How do I determine the owner of a process in C#?](http://stackoverflow.com/questions/777548/how-do-i-determine-the-owner-of-a-process-in-c) – sll Oct 26 '11 at 14:18
-
from the http://msdn.microsoft.com/en-us/library/system.environment.username.aspx "Gets the user name of the person who is currently logged on to the Windows operating system." so IMHO it sounds like it's not the same as the process owner. The process is started somewhere inside of asp.mvc app. – Cyryl Płotnicki Oct 26 '11 at 14:26
2 Answers
1

Davide Piras
- 43,984
- 10
- 98
- 147
-
Hi, thanks. Docs for GetUserNameEx: "Retrieves the name of the user or other security principal associated with the calling thread. You can specify the format of the returned name. If the thread is impersonating a client, GetUserNameEx returns the name of the client." Sounds legit and is fine for me. However, are you sure that WindowsIdentity.GetCurrent().Name; gives exactly the same results ? Maybe so, but i couldn't find it in docs. – Cyryl Płotnicki Oct 26 '11 at 14:40
0
Although not .net, the following article from the Unix to Windows Porting Dictionary on:
uid_t getuid();
uid_t geteuid();
... is a good start to solving this problem.
From that article:
A Unix process maintains a distinction between the UID of the user that started the process (the real UID) and the UID of the user that the process is running as (the effective UID). Windows does not maintain this distinction. The value of a SID will be the equivalent of the Unix effective UID. Since the equivalent of the Unix real UID cannot be obtained using the SID is recommended for Windows when the real or effective UID is needed.

Michael Goldshteyn
- 71,784
- 24
- 131
- 181