Click here to Skip to main content
15,911,317 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have a requirement in our project to launch a executable from a VC++ code. In Windows XP, every thing is working fine. But when in Windows 7, because of its UAC, the application which is getting launched as normal user.

In other words, consider "Application A" is launched from "Application B" (this is MFC application). Even though "Application B" is launched as administrator, "Application A" is launched as normal.

I have found few articles on internet which deals with Registry entries. Can anyone suggest a simple way to acheive this.

Thanks in Advance...
Posted
Comments
JackDingler 16-Nov-11 14:37pm    
Can you post the code in which you launch the app?

CreateProcess with NULLs in the security descriptor whould give the new app the same rights as the app that spawned it.

If you need the UAC to popup, then use ShellExecute().

Not sure about CreateProcess in Win 7, but I wouldn't be surprised if it's default behavior was to spawn the process with normal user level privileges rather than the elevated "admininistrator" privilege level of the spawning process. That would be the secure thing to do.

You might be able to spawn the process with CreateProcess and specify the security descriptor to ensure you get what you want, rather than passing null -- it's not clear from the documentation but I'd give it a try.

That said, it seems that the way Microsoft recommends to do this is to modify the registry, see "Running As Administrator":

http://msdn.microsoft.com/en-us/library/windows/desktop/ms717801(v=vs.85).aspx[^]

It's possible you could acheive the same effect using CreateProcessAs

(See: http://msdn.microsoft.com/en-us/library/windows/desktop/ms682429(v=vs.85).aspx[^])

or using CreateProcessWithLogonW

(See: http://msdn.microsoft.com/en-us/library/windows/desktop/ms682431(v=vs.85).aspx[^])

Check it out and see if either of those will let you do what you want.
 
Share this answer
 
Comments
Albert Holguin 17-Nov-11 14:09pm    
Good info, +5
MSDN library has very nice example code

http://code.msdn.microsoft.com/CSRunProcessAsUser-e4b10d6f[^] this explains a lot about different user privileges , You might really learn a lot from it ..
 
Share this answer
 
Finally After many trials, i found the solution.

We can use ShellExecute.

Eg: ShellExecute(NULL, NULL, _T("D:\\AdminLaunch_CSharp.exe"), NULL, NULL, SW_SHOW);

This launches the application "AdminLaunch_CSharp.exe" with the same privilages as of that of launching application.

Thanks guys. I actually got pointers from all of your replies
 
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