Link to home
Start Free TrialLog in
Avatar of sarah81
sarah81

asked on

CreateProcessAsUser gives "Required privilege not held" error

Hi,
I am writing code to run an exe using an account other than the currently logged in account. For that I have got token of another user by using LogonUser() and then I try to run my exe using CreateProcessAsUser(). It gives me error 1314: A required privilege is not hel by the client. Which privilege does my user doesnt have. I have even tried to use this method with the Administrator account, but the same problem occurs. My user has the following privileges:

 --------------                   ------------
SeTcbPrivilege                   Act as part of the operating system
SeChangeNotifyPrivilege          Bypass traverse checking
SeShutdownPrivilege              Shut down the system
SeUndockPrivilege                Remove computer from docking station

Which privilege am I missing?

Thanks in advance,
Sarah.
Avatar of cookre
cookre
Flag of United States of America image

At least SE_ASSIGNPRIMARYTOKEN_NAME and maybe SE_INCREASE_QUOTA_NAME.

If you've the rights, you can grant them to yourself with AdjustTokenPrivileges().
Avatar of sarah81
sarah81

ASKER

Yeah this what MSDN says that you must have  SE_ASSIGNPRIMARYTOKEN_NAME , SE_INCREASE_QUOTA_NAME and SE_TCB_NAME to use CreateProcessAsUser().

But at the same time, MSDN also says: "The AdjustTokenPrivileges function cannot add new privileges to the access token. It can only enable or disable the token's existing privileges."

And my token [that i got from LogonUser( ) ] doesnt have these rights.
What to do?
CreateProcessAsUser usually only works from inside a service.

Can you use CreateProcessWithLogonW? That doesn't need as much privileges. The only problem of this API is that it isn't supported in NT4.
Avatar of sarah81

ASKER

I am using Visual Studio 6.0 and Microsoft SDK 2003 on Windows 2000. I have included windows.h in my project,yet it gives "Undeclared identifier" error when I try to use CreateProcessWithLogonW().

I am not sure if the problem is related to services because I am able to successfully logon the other account by using LogonUser().

I think cookre is right, the reason CreateProcessAsUser() fails is that it doesnt have these 2 privileges. But the problem is, I cant find any API to assign a user privileges that arent held by him. And my user holds only the 4 privileges that I mentioned in my question.
See here about CreateProcessWithLogonW:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/createprocesswithlogonw.asp

About privileges: If everyone could just assign any privilege to himself, what would privileges be worth anymore? They are meant to be a secure way to limit the rights of a specific user. So of course Microsoft made sure that you can't get around that too easily.
Avatar of sarah81

ASKER

Ok another problem. CreateProcessAsUser() now works with the Administrator user but for other users, it gives error "The application failed to initialize properly (0xc0000142). Click OKto terminate the application".
Why?? It cant be a privilege problem, becuase in that case it would have given "required privilege not held prob rather than this one"

Does anyone know the solution to this prob?? Why am i getting this error for some users (and not all) and why am i getting this error in the first place?
I am just trying to run cmd.exe from the method.

Thanks.
Avatar of sarah81

ASKER

I have found solution to all the above problems.

(1) For the first problem (required privileges not held), the privileges were to be assigned to the user who is currently logged on (not the user whom we log on through LogonUser() ). If you are logged through the local Admin, you can always use CreateProcessAsUser without trouble. If you are logged on through someother account,  you wil have to assign yourself the 3 rights  SE_ASSIGNPRIMARYTOKEN_NAME , SE_INCREASE_QUOTA_NAME and SE_TCB_NAME to successfully call LogonUser and CreateProcessAsUser.

(2) As for the "applicaton failed to initialize 0xc0000142" error, its windows security that it doesnt allow someone to user others' account. So you have to go a long way to achieve that.  See Microsoft Knowledge Base Article  Q165194 "INFO: CreateProcessAsUser() Windowstations and Desktops " in the MSDN. It shows how to obtain and SID and then use it for this purpose.


ASKER CERTIFIED SOLUTION
Avatar of GhostMod
GhostMod
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial