是否有可能只能通过code以管理员身份运行 [英] Is it possible to run as administrator only through code

查看:444
本文介绍了是否有可能只能通过code以管理员身份运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

操作系统:Windows
语言:C

OS: Windows Language: C

我有一个要求,例如,我不应该改变的exe文件的清单或exe文件的运行它以管理员身份属性。有没有做我的要求与CreateProcess的/ createprocessasuser API的任何机会。这可以通过API的ShellExecute来完成,但是我需要创建我处于暂停状态的过程。这只能通过CreateProcess的或createprocessasuser API来完成。
这将不胜感激,如果有人能指导我通过这些API运行一个程序作为管理员。

I have a requirement such as , I should not change the exe's manifest or the exe file's properties to run it as administrator. Is there any chance in doing my requirement with createprocess/createprocessasuser api. This can be done through shellexecute api, However I need to create my process in suspended state. this can only be done by createprocess or createprocessasuser api. It would be grateful,If some one can guide me in running a program as administrator through these api.

推荐答案

我觉得最简单的解决办法是途径你要推出,虽然的runas /用户的过程:管理员yourprocess.exe 或提供运行方式字符串为的ShellExecute 的第二个参数。这似乎是无证功能强悍。

I think the easiest solution would be to route the process you're trying to launch though runas /user:administrator "yourprocess.exe" or supply the runas string literal to the second parameter of ShellExecute. This seems to be an undocumented feature tough.

ShellExecute(
    NULL,
    _T("runas"),
    _T("notepad.exe"),
    _T(""),    // params
    NULL,        // directory
    SW_SHOW
);

这篇关于是否有可能只能通过code以管理员身份运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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