简体   繁体   中英

Run ui application with admin rights from service in current user's context

I want to create a service. This service will do some diagnostics on current logon user's session. For example invoke some WMI commands. as you know when you connect to WMI as service you cannot see items ( for example printers or something else ) specific to user's session

So I started my research and I came up with CreateProcessAsUser() (because I don't know current user's password this seemed to me like it will do the job).

I have succefully got active session id and got token from session and duplicated session and called process as currently logon user. But the problem is when i call another exe its called without elevated rights. I'm stucked at this point.

My questions:

  1. is it possible to call another exe as user but with admin rights ?

  2. Is this correct and modern approach to this problem? I mean I read some people suggest to create 2 components. One is some simple application which will run at user's context other is service. This service and small application will communicate.

  3. If i choose to go with 2, is it possible to start this small application on user's context with admin rights from the service?

EDIT:

I think i got close but little bit confused. If i Duplicate the token as i told i get user session but without admin rights. But instead of duplicate if i get linked token ( as i read its admin token) i get it following way

 IntPtr adminToken = IntPtr.Zero;
 uint TokenInfLength = 0;
 GetTokenInformation(hToken, 
 TOKEN_INFORMATION_CLASS.TokenLinkedToken, adminToken, 
 TokenInfLength,out TokenInfLength);

my process runs as admin but not in logon user's context it runs as system's context i cannot see user specific data. I don't understand how to give this token rights to currently logon user

it is possible ie you can use DuplicateToken function and then CreateProcessAsUser with duplicated token and elevated privileges.

To work under service this functions are required some changes in local policies

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM