Prisy,
In order to do that, you would have to get a handle to the process you
want to get the username for first. Assuming you have that, you will have
to do a bit of P/Invoke calls to get it.
First, you would call OpenProcessToken. Once you have the token for the
process, you would call GetTokenInformation passing the value TokenUser for
the TokenInformationClass parameter. This will return a TOKEN_USER
structure which contains the SID for the user that the process was launched
under. The only field that the TOKEN_USER structure has is of type
SID_AND_ATTRIBUTES, which has two fields, Sid and Attributes. The Sid field
is the pointer to the SID. With that, you can call the LookupAccountSid
function, passing the pointer to the SID and getting the domain and user
that the process was started under.
You should be able to find most of the definitions for these functions
at
http://www.pinvoke.net. If they are not there, post back, and we can
help you with the definitions.
Hope this helps.