CreateProcessAsUser gives "Required privilege not held" error

Posted on 2004-08-30
Last Modified: 2013-12-03
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,
Question by:sarah81
LVL 22

Expert Comment

ID: 11938921

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

Author Comment

ID: 11939139
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?
LVL 20

Expert Comment

ID: 11939441
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.
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.


Author Comment

ID: 11939494
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.
LVL 20

Expert Comment

ID: 11939537
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.

Author Comment

ID: 11987247
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.


Author Comment

ID: 11988749
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.


Accepted Solution

GhostMod earned 0 total points
ID: 12030038
PAQd, 250 points refunded.

Community Support Moderator

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question