<tfoot id='UXLwx'></tfoot>

<small id='UXLwx'></small><noframes id='UXLwx'>

    <legend id='UXLwx'><style id='UXLwx'><dir id='UXLwx'><q id='UXLwx'></q></dir></style></legend>

      • <bdo id='UXLwx'></bdo><ul id='UXLwx'></ul>

      <i id='UXLwx'><tr id='UXLwx'><dt id='UXLwx'><q id='UXLwx'><span id='UXLwx'><b id='UXLwx'><form id='UXLwx'><ins id='UXLwx'></ins><ul id='UXLwx'></ul><sub id='UXLwx'></sub></form><legend id='UXLwx'></legend><bdo id='UXLwx'><pre id='UXLwx'><center id='UXLwx'></center></pre></bdo></b><th id='UXLwx'></th></span></q></dt></tr></i><div id='UXLwx'><tfoot id='UXLwx'></tfoot><dl id='UXLwx'><fieldset id='UXLwx'></fieldset></dl></div>
      1. 如何运行需要管理员权限的应用程序

        时间:2023-07-31

          <tbody id='jaJHx'></tbody>
        <tfoot id='jaJHx'></tfoot>

        <small id='jaJHx'></small><noframes id='jaJHx'>

          • <bdo id='jaJHx'></bdo><ul id='jaJHx'></ul>

            <legend id='jaJHx'><style id='jaJHx'><dir id='jaJHx'><q id='jaJHx'></q></dir></style></legend>

                • <i id='jaJHx'><tr id='jaJHx'><dt id='jaJHx'><q id='jaJHx'><span id='jaJHx'><b id='jaJHx'><form id='jaJHx'><ins id='jaJHx'></ins><ul id='jaJHx'></ul><sub id='jaJHx'></sub></form><legend id='jaJHx'></legend><bdo id='jaJHx'><pre id='jaJHx'><center id='jaJHx'></center></pre></bdo></b><th id='jaJHx'></th></span></q></dt></tr></i><div id='jaJHx'><tfoot id='jaJHx'></tfoot><dl id='jaJHx'><fieldset id='jaJHx'></fieldset></dl></div>
                  本文介绍了如何运行需要管理员权限的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我已经坚持了几个小时,直到我终于设法做到了.已经有链接为我指明了正确的方向:

                  I've been stuck on this for a few hours until I've finally managed to do it. There are already links which pointed me the right direction:

                  • 有可能吗对于可执行文件要求管理员权限?(Windows 7)
                  • CreateProcess error=740,请求的操作需要提升

                  但我认为对问题的简单概述可以帮助某人:)

                  But I've thought that simple overview of the problem could help someone :).

                  推荐答案

                  真正的问题:(来自维基百科:http://en.wikipedia.org/wiki/User_Account_Control)

                  Real problem: (from Wikipedia: http://en.wikipedia.org/wiki/User_Account_Control)

                  标记为requireAdministrator"的可执行文件;在其清单中不能使用 CreateProcess() 从非提升进程启动.相反,将返回 ERROR_ELEVATION_REQUIRED.必须改用 ShellExecute() 或 ShellExecuteEx().

                  An executable that is marked as "requireAdministrator" in its manifest cannot be started from a non-elevated process using CreateProcess(). Instead, ERROR_ELEVATION_REQUIRED will be returned. ShellExecute() or ShellExecuteEx() must be used instead.

                  (顺便说一句,ERROR_ELEVATION_REQUIRED 错误 == 740)

                  (BTW, ERROR_ELEVATION_REQUIRED error == 740)

                  解决方案:(同一站点)

                  Solution: (same site)

                  在本机 Win32 应用程序中,相同的runas"动词可以添加到 ShellExecute() 或 ShellExecuteEx() 调用中.

                  In a native Win32 application the same "runas" verb can be added to a ShellExecute() or ShellExecuteEx() call.

                  ShellExecute(hwnd, "runas", "C:\Windows\Notepad.exe", 0, 0, SW_SHOWNORMAL);

                  这可能也有帮助:(来源:http://mark.koli.ch/2009/12/uac-prompt-from-java-createprocess-error740-the-requested-operation-requires-elevation.html)

                  This may be also helpful: (source: http://mark.koli.ch/2009/12/uac-prompt-from-java-createprocess-error740-the-requested-operation-requires-elevation.html)

                  2 - 基本的 UAC 流程

                  2 - Basic UAC Flow

                  好的,所以在您深入研究之前,我认为解释 UAC 感知应用程序的基本流程以及所有内容如何组合在一起可能会有所帮助.通常,您的应用程序以非特权用户身份运行.但是,有时它需要是管理员(做任何事情).所以,这是伪代码中的基本思想:

                  Ok, so before you dig into it, I thought it might be helpful to explain the basic flow of a UAC aware application and how everything fits together. Normally, your application runs as an unprivileged user. But, sometimes it needs to be an Administrator (to do whatever). So, here's the basic idea, in pseudo code:

                  int main (int argc, char **argv) {
                  
                    HRESULT operation = tryToDoSomethingPrivileged();
                  
                    if (operation == ACCESS_DENIED && !alreadyElevated) {
                  
                      // Spawn a copy of ourselves, via ShellExecuteEx().
                      // The "runas" verb is important because that's what
                      // internally triggers Windows to open up a UAC prompt.
                      HANDLE child = ShellExecuteEx(argc, argv, "runas");
                  
                      if (child) {
                        // User accepted UAC prompt (gave permission).
                        // The unprivileged parent should wait for
                        // the privileged child to finish.
                        WaitForSingleObject(child, INFINITE);
                        CloseHandle(pid);
                      }
                      else {
                        // User rejected UAC prompt.
                        return FAILURE;
                      }
                  
                      return SUCCESS;
                  
                    }  
                  
                    return SUCCESS;
                  
                  }
                  

                  最后,我是这样做的:

                  if(0 == CreateProcess(argv[2], params, NULL, NULL, false, 0, NULL, NULL, &si, &pi)) {
                          //runas word is a hack to require UAC elevation
                          ShellExecute(NULL, "runas", argv[2], params, NULL, SW_SHOWNORMAL);
                  }
                  

                  为了完整起见 - MSDN 链接到 ShellExecute 和 CreateProcess:

                  And just for completness's sake - MSDN links to ShellExecute and CreateProcess:

                  http://msdn.microsoft.com/en-us/library/bb762153%28v=vs.85%29.aspx

                  http://msdn.microsoft.com/en-us/library/ms682425%28VS.85%29.aspx

                  这篇关于如何运行需要管理员权限的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何检查程序是否从控制台运行? 下一篇:C++/Win32:如何等待挂起的删除完成

                  相关文章

                  最新文章

                • <i id='lwuKM'><tr id='lwuKM'><dt id='lwuKM'><q id='lwuKM'><span id='lwuKM'><b id='lwuKM'><form id='lwuKM'><ins id='lwuKM'></ins><ul id='lwuKM'></ul><sub id='lwuKM'></sub></form><legend id='lwuKM'></legend><bdo id='lwuKM'><pre id='lwuKM'><center id='lwuKM'></center></pre></bdo></b><th id='lwuKM'></th></span></q></dt></tr></i><div id='lwuKM'><tfoot id='lwuKM'></tfoot><dl id='lwuKM'><fieldset id='lwuKM'></fieldset></dl></div>

                  <legend id='lwuKM'><style id='lwuKM'><dir id='lwuKM'><q id='lwuKM'></q></dir></style></legend>
                    <tfoot id='lwuKM'></tfoot>

                        <bdo id='lwuKM'></bdo><ul id='lwuKM'></ul>
                    1. <small id='lwuKM'></small><noframes id='lwuKM'>