从具有管理员权限的VC ++应用程序启动可执行文件 [英] Launch an executable from an VC++ application with administrator privilages

查看:283
本文介绍了从具有管理员权限的VC ++应用程序启动可执行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我的项目中要求从VC ++代码启动可执行文件.在Windows XP中,一切正常.但是在Windows 7中,由于其UAC,该应用程序将以普通用户身份启动.

换句话说,请考虑从应用程序B"(这是MFC应用程序)启动应用程序A".即使以管理员身份启动了应用程序B",但仍正常启动了应用程序A".

我在互联网上发现了一些有关注册表项的文章.任何人都可以提出实现这一目标的简单方法.

在此先感谢...

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...

推荐答案

不确定Win 7中的CreateProcess,但是如果它的默认行为是生成该文件,我不会感到惊讶.具有普通用户级别特权的进程,而不是产生过程的提升的管理员"特权级别.那将是安全的事情.

您也许可以使用CreateProcess生成该过程并指定安全描述符以确保获得所需的内容,而不是传递null -从文档中尚不清楚,但我可以尝试一下. />
就是说,微软似乎建议这样做的方法是修改注册表,请参阅以管理员身份运行":

http://msdn.microsoft.com/zh-CN /library/windows/desktop/ms717801(v=vs.85).aspx [ http://msdn.microsoft.com/zh-cn/library/windows/desktop/ms682429(v = vs.85).aspx [ http://msdn.microsoft.com/zh-cn/library/windows/desktop/ms682431(v = vs.85).aspx [
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.


MSDN库具有非常好的示例代码

http://code.msdn.microsoft.com/CSRunProcessAsUser-e4b10d6f [
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 ..


最后经过多次试验,我找到了解决方法.

我们可以使用ShellExecute.

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

这将以与启动应用程序相同的特权启动应用程序"AdminLaunch_CSharp.exe".

多谢你们.我实际上从您的所有答复中得到了指点
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


这篇关于从具有管理员权限的VC ++应用程序启动可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆