Click here to Skip to main content
15,888,056 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi,all

I've wrote a service program on win7, and I need to create a process as Admin in that service. Here is what I did:
1.Get the access token of the log on user
2.Call CreateProcessAsUser() function to create that process.

Now I can get the right access token, but when I call createprocessasuser, it fails with error message "Requested action requires elevated"。

How can I create a process as Admin in my windows service program anyway?

Thanks.
Posted

C#
ProcessStartInfo processStartInfo = new ProcessStartInfo
                                        { FileName = "calc.exe" };

if (Environment.OSVersion.Version.Major >= 6)
    processStartInfo.Verb = "runas"; // Windows Server 2008, Vista or higher;
                                     // User will be prompted

processStartInfo.Arguments = "";
processStartInfo.WindowStyle = ProcessWindowStyle.Normal;
processStartInfo.UseShellExecute = true;

Process process = null;
try
{
    process = Process.Start(processStartInfo);
}
catch (Exception ex)
{
    // Exception handling here
}
finally
{
    if (process != null)
        process.Dispose();
}


However I would not suggest you do this, unless your service runs with administrative rights, as the user will be prompted to allow the application to be run with elevated permissions on Windows Server 2008, Vista and 7.
 
Share this answer
 
you can impersonate the admin user to do Some Admin Task.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900