• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 23402
  • Last Modified:

CreateProcessAsUser gives "Required privilege not held" error

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,
1 Solution

If you've the rights, you can grant them to yourself with AdjustTokenPrivileges().
sarah81Author Commented:
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.
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

sarah81Author Commented:
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:


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.
sarah81Author Commented:
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.

sarah81Author Commented:
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.

PAQd, 250 points refunded.

Community Support Moderator
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now