Solved

Run a process as admin from a system account in Windows

Posted on 2008-11-03
3
618 Views
Last Modified: 2013-12-04
Hello experts,

I'm running a process under the system account, and I want it to run another process as another user (of course, supplying the username and password).

I'm using the CreateProcessWithLogonW API function, which works fine when my process runs with any account, but NOT under system account... When running on system account, GetLastErr returns 5 (ACCESS_IS_DENIED).

I've tried altering the dwLogonFlags parameter, but in both flags (LOGON_WITH_PROFILE and LOGON_NETCREDENTIALS_ONLY) it behaves the same...
0
Comment
Question by:Iys
  • 2
3 Comments
 
LVL 6

Expert Comment

by:ChristianWimmer
ID: 22866668
The CreateProcessWithLogonW function does not work in a SYSTEM account. It is a "known" bug. However you can user LogonUser and CreateProcessAsUser from your service like here:

http://www.experts-exchange.com/Programming/System/Windows__Programming/Q_20687952.html?sfQueryTermInfo=1+createprocessasus

0
 

Author Comment

by:Iys
ID: 22875169
OK... not very successful:
The LogonUser func failed with the LOGON32_LOGON_BATCH logon type (as well as LOGON32_LOGON_SERVICE), and all other logon types makes the CreateProcessAsUser function fail.
The LOGON32_LOGON_NEW_CREDENTIALS logon type is the only logon type not failing the child process creation, but the child process runs under SYSTEM account again!...
0
 
LVL 6

Accepted Solution

by:
ChristianWimmer earned 500 total points
ID: 22875253
Oh I did not see that this example uses another logon type. You should use LOGON32_LOGON_INTERACTIVE .
In a service you also need to set the token session ID using SetTokenInformation, because users may run in another session than the service (vista).

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

747 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now