- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
一些由普通用户启动的应用程序会在必要时请求提升权限(例如,文件管理器需要写入此类文件夹),然后继续操作。
我怎样才能复制这种行为?
最佳答案
正如 Tamás 指出的那样,您需要启动一个具有更高权限的新流程。之前找了很多都没有找到给当前进程提权的方法。
假设您的主要应用程序是 App1.exe,然后您调用需要提升权限的辅助进程 App2.exe。
A.您可以在 App2.exe 中嵌入 list ,但更简单的方法是创建一个名为 App2.exe.manifest 的 list 文件 [文本文件],内容如下,并将其放在与 App2.exe 相同的目录中。笔记: !!奇怪的是,如果您的应用程序名称不是 App2.exe,而是 App2_install.exe 或 App2_setup.exe(即,如果应用程序名称包含“install”或“setup”),Windows Vista/Windows 7 中将自动出现一个 UAC 对话框即使没有 list 文件也会要求提升权限!!这是 list 文件的示例:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
B.您可以在 App1.exe 中使用如下代码启动 App2.exe
QString AppToExec = qApp->applicationDirPath() + "/App2.exe";
// Put any required parameters of App2.exe to AppParams string
QString AppParams = "";
if (0 != genWin32ShellExecute(AppToExec,
"", // default verb: "open" or "exec"
AppParams,
false, // run hidden
true)) // wait to finish
{
// (...) handle error
}
...最后,这是我创建的 Win32 函数 genWin32ShellExecute() 的代码,用于在 Win32 操作系统上使用 QT 时启动进程或打开文档:
标题:
#ifdef Q_OS_WIN // Implement genWin32ShellExecute() especially for UAC
#include "qt_windows.h"
#include "qwindowdefs_win.h"
#include <shellapi.h>
int genWin32ShellExecute(QString AppFullPath,
QString Verb,
QString Params,
bool ShowAppWindow,
bool WaitToFinish);
#endif
CPP:
// Execute/Open the specified Application/Document with the given command
// line Parameters
// (if WaitToFinish == true, wait for the spawn process to finish)
//
// Verb parameter values:
// "" The degault verb for the associated AppFullPath
// "edit" Launches an editor and opens the document for editing.
// "find" Initiates a search starting from the specified directory.
// "open" Launches an application. If this file is not an executable file, its associated application is launched.
// "print" Prints the document file.
// "properties" Displays the object's properties.
//
// Ret: 0 = success
// <0 = error
#ifdef Q_OS_WIN
int genWin32ShellExecute(QString AppFullPath,
QString Verb,
QString Params,
bool ShowAppWindow,
bool WaitToFinish)
{
int Result = 0;
// Setup the required structure
SHELLEXECUTEINFO ShExecInfo;
memset(&ShExecInfo, 0, sizeof(SHELLEXECUTEINFO));
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
if (Verb.length() > 0)
ShExecInfo.lpVerb = reinterpret_cast<const WCHAR *>(Verb.utf16());
ShExecInfo.lpFile = NULL;
if (AppFullPath.length() > 0)
ShExecInfo.lpFile = reinterpret_cast<const WCHAR *>(AppFullPath.utf16());
ShExecInfo.lpParameters = NULL;
if (Params.length() > 0)
ShExecInfo.lpParameters = reinterpret_cast<const WCHAR *>(Params.utf16());
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = (ShowAppWindow ? SW_SHOW : SW_HIDE);
ShExecInfo.hInstApp = NULL;
// Spawn the process
if (ShellExecuteEx(&ShExecInfo) == FALSE)
{
Result = -1; // Failed to execute process
} else if (WaitToFinish)
{
WaitForSingleObject(ShExecInfo.hProcess, INFINITE);
}
return Result;
}
#endif
关于c++ - 我如何在运行时要求用户提升权限?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6108851/
在本教程中,您将通过示例学习 JavaScript。 JavaScript 中的提升是一种在声明之前可以使用函数或变量的行为。例如, // using test before declarin
我正在学习javascript提升功能,发现下面的代码真的很困惑: var a = 1; function b() { a = 10; return; function a()
作为一个JS学习者,我发现了一件很有趣的事情,考虑下面的代码。 this.init = function (e) { var container = e.container;
Quasiquotes 的 Scala 文档在解释 Lifting 时提到了这一点: One can also combine lifting and unquote splicing: scala
我是新来的。到目前为止,我一直在使用 MVC 模型并使用基本的 session 管理模型,即在 session 中存储一个 token 并检查每个请求。 我正在尝试对lift做同样的事情,但我的 se
我当前使用的是Elasticsearch 2.4版,希望根据查询时间的增加或加权,根据我称为“类型”的字段对结果集进行微调。 例如 如果字段“类型”的值为“船”,则将权重或增强值增加4 如果字段“类型
一年多以来,我一直在大量使用 lift、return 以及 EitherT、ReaderT< 等构造函数,等等。我读过《Real World Haskell》、《Learn You a Haskell
我浏览了电梯的MegaProtoUser遇到这种结构:??("Last Name")。谁能解释一下,这是什么意思? 谢谢解答 最佳答案 它是在对象 S 上定义的: def ??(str : Strin
我有一个Solr索引,每个文档都是一个Event的信息。在我的架构中,Schedule 是日期类型的多值字段。我想知道是否可以使用计划日期来增加文档(多值字段中的任何日期)在未来并且最接近当前日期?我
作为测试,我正在尝试使用设计人员友好的模板在 lift 中创建一个表单。我正在使用 Lift 2.5 我已经设法使用 toForm 创建了一个工作表单,但我只是在探索所有可能的方法。 我的 html
如果这个问题已经被问到,我深表歉意。 是否可以清除已经设置的条件变量? 下面是我想要实现的详细信息: void worker_thread { while (wait_for_conditio
尝试学习Js,无法理解为什么DOM元素没有获取到值: var Car = function(loc) { var obj = Object.create(Car.prototype); obj
我想知道吊装。我知道如果全局函数名称与全局变量相同,函数会覆盖变量的名称。是吗? 这是我的代码。 (function() { console.log('console.log#1 ' + glob
这个问题已经有答案了: var functionName = function() {} vs function functionName() {} (41 个回答) 已关闭 7 年前。 在javas
我正在开发 Windows 资源管理器 namespace 扩展。我的应用程序是explorer.exe在某个时候加载和使用的动态库。我需要我的 DLL 在 C:\中创建文件,有时在其他需要提升才能执
背景: GitHub 属于客户。我们团队中有一些新手,他们有时会错过基本的命名约定和其他编码协议(protocol)。所以,如果哪位前辈想在内部review,除了创建PR,别无他法。但是这个 PR 对
我们需要在运行时更改 HKEY_LOCAL_MACHINE 的一些设置。 如果需要在运行时,是否可以提示 uac 提升,或者我是否必须启动第二个提升的进程来完成“肮脏的工作”? 最佳答案 我会以提升的
看着Haskell文档,提升似乎基本上是 fmap 的概括,允许映射具有多个参数的函数。 Wikipedia然而,关于提升的文章给出了不同的观点,根据类别中的态射来定义“提升”,以及它如何与类别中的其
ggplot2 package 很容易成为我用过的最好的绘图系统,除了对于较大的数据集(约 50k 点)性能不是很好。我正在研究通过 Shiny 提供网络分析,使用 ggplot2作为绘图后端,但我对
是否可以提升 powershell 脚本的权限,以便没有管理员权限的用户可以运行该脚本?我们的网络管理员正在尝试寻找更省时的方法来完成某些任务,目前他们必须使用远程桌面...使用 PS 脚本将其自动化
我是一名优秀的程序员,十分优秀!