tags:

views:

62

answers:

4

There is any way to run another process with ordinary rights from a process running as administrator? From a process with elevated rights I want to start a process with ordinary rights like it were started from explorer. I tried impersonation but I didn't work.

A: 

on linux you can use setuid to change the program user id

for windows you can look at his: http://serverfault.com/questions/16886/is-there-an-equivalent-of-su-for-windows

jojo
+2  A: 

Use CreateProcessAsUser(). Details are in the linked SDK docs.

Hans Passant
And where would you get the token from?
Anders
@Anders - LogonUser() returns that token.
Hans Passant
@nobugz - And where do you get the username and password for LogonUser?
Anders
@Anders - ask the user. That had a dangerously high doh! level.
Hans Passant
+1  A: 

No this is not possible (There are several hacky ways to do this (Inject into explorer, task scheduler, SaferAPI+MediumIL etc) but none of them work in all scenarios)

Anders
The problem is that it's REALLY hard to split your token back the way it was when winlogon created it. Your best bet is to have a medium IL application that launches your application elevated. When you want to execute code as the standard user, just IPC the request to the medium IL launching application.
Larry Osterman
A: 

This seems like a nice way to do it, provided you don't care about situations where the Shell is not running (e.g. possibly some Terminal Services application-only setups, perhaps, though I'm not sure):

http://brandonlive.com/2008/04/27/getting-the-shell-to-run-an-application-for-you-part-2-how/

It gets an interface to Explorer.exe, which should be running in the user's normal context, and asks Explorer to execute a command in its behalf. This is done just using simple, documented COM interfaces and without having to mess around with process tokens or code/DLL injection.

Leo Davidson