C ++控制台应用程序提示“以管理员身份运行”以管理员身份运行? [英] C++ Console Application prompt "Run as Admin" to run as administrator?

查看:219
本文介绍了C ++控制台应用程序提示“以管理员身份运行”以管理员身份运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何让C ++命令应用程序以管理员身份运行?

How can i make a C++ Command Application run as admin?

程序创建需要管理员权限,所以最好让用户获得运行管理员提示。

the program im creating needs administrator rights so it would be nice to let the user get the run as admin prompt. How may i do that?

注意:我没有使用Visual Studio,im使用Code :: Blocks 10.05;

NOTE: Im not using Visual Studio, im using Code::Blocks 10.05;

-Stian

推荐答案

您可以创建一个清单文件,说明应用程序需要升级到管理员。这是一个普通的文本文档,您可以在记事本中创建,并在应用程序执行时由Windows加载。

You can create a manifest file to state that the application requires elevation to administrator. It's a normal text document that you can create in Notepad and it's loaded by Windows when the application is executed.

这是一个清单的示例, c $ c> MyApplication 。

Here's an example of a manifest, for an application called MyApplication.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> 
  <assemblyIdentity version="1.0.0.0"
     processorArchitecture="X86"
     name="MyApplication"
     type="win32"/> 
  <description>Description of your application</description> 
  <!-- Identify the application security requirements. -->
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel
          level="requireAdministrator"
          uiAccess="false"/>
        </requestedPrivileges>
       </security>
  </trustInfo>
</assembly>

然后将其命名为 MyApplication.exe.manifest MyApplication 替换为任何可执行文件名称),它将由UAC自动加载。

Then simply name it MyApplication.exe.manifest (replacing MyApplication with whatever your executable name is) and it'll get loaded by UAC automatically.

有关详细信息,请参阅此处: http://msdn.microsoft.com/en-us/library/bb756929.aspx

See this for more details: http://msdn.microsoft.com/en-us/library/bb756929.aspx

这篇关于C ++控制台应用程序提示“以管理员身份运行”以管理员身份运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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