Solved

Run a process as admin from a system account in Windows

Posted on 2008-11-03
3
623 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
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. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

809 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